---
title: "LinkedIn & Meta API Error 400: Invalid Image Dimensions & How to Fix It"
description: "LinkedIn and Meta reject images that don't match a 1.91:1 aspect ratio. Ayrshare explains the Invalid Image Dimensions error and how auto-resizing fixes it."
canonical: https://www.ayrshare.com/solutions/linkedin-meta-api-error-400-invalid-image-dimensions-how-to-fix-it/
lastModified: 2026-07-09
pageType: solution
---

# LinkedIn & Meta API Error 400: Invalid Image Dimensions & How to Fix It

> LinkedIn and Meta reject images that don't match a 1.91:1 aspect ratio. Ayrshare explains the Invalid Image Dimensions error and how auto-resizing fixes it.

## LinkedIn & Meta API Error 400: Invalid Image Dimensions & How to Fix It

[Start free trial](https://app.ayrshare.com)
[View pricing](/pricing/)

You've built a flawless content publishing flow, dynamically generating beautiful graphics for your users. You fire off a POST request to LinkedIn or Meta's Graph API, fully expecting a perfectly rendered OpenGraph card. Instead, your server gets slapped with an HTTP 400: Invalid Image Aspect Ratio or a cryptic Asset Validation Failed error.

Your image looks fine in the browser. So why did the API choke on it? You've just hit the invisible, rigid wall of social media Aspect Ratio requirements.

## The "Why" Behind the Validation Failure

Social platforms are ruthlessly protective of their UI layouts. When you pass an image URL for an OpenGraph link preview or a direct media upload, the native platform APIs don't just accept any file you throw at them. They strictly enforce dimensions.

For OpenGraph and standard link cards, the golden Aspect Ratio is almost always 1.91:1 (ideally 1200x627 pixels). If you send a tall 9:16 portrait image or a tiny 300x300 avatar, the API will either reject the request outright or, worse, brutally Crop the center of your image, cutting off vital text and logos.

Furthermore, you have to contend with the JPG vs PNG dilemma. While PNGs are great for vectors, platforms often reject them if they exceed conservative file size limits or contain unexpected alpha channels (transparency) that render as ugly black boxes in dark mode. To ensure API acceptance, you need to flatten, resize, and compress your media before the request ever leaves your server.

## The Manual Fix: Pre-Processing with Sharp

To solve this natively, you have to build an image processing middleware layer that intercepts user media and brute-forces it into the 1.91:1 specification. Here is a Node.js implementation using the sharp library to automatically resize, smart-crop, and flatten images before hitting the native APIs.

```javascript
const sharp = require("sharp");
const axios = require("axios");

// Normalizes arbitrary images into a strict 1.91:1 OpenGraph/Social format
async function formatForSocialMedia(imageUrl) {
  try {
    // 1. Fetch the raw image from your storage or user upload
    const response = await axios({ url: imageUrl, responseType: "arraybuffer" });
    const imageBuffer = Buffer.from(response.data, "binary");

    // 2. Process with Sharp
    const processedImage = await sharp(imageBuffer)
      .resize(1200, 627, {
        fit: "cover",        // Enforce the exact 1.91:1 aspect ratio
        position: "entropy"  // Smart crop: focuses on the most "interesting" part of the image
      })
      .flatten({ background: "#ffffff" }) // Flatten PNG transparency to a white background
      .jpeg({ quality: 90 })              // Force JPG to bypass PNG payload limits
      .toBuffer();

    return processedImage;
  } catch (error) {
    console.error("Image processing failed:", error.message);
    throw error;
  }
}

// Usage:
// const safeBuffer = await formatForSocialMedia("https://example.com/raw_user_image.png");
// Then initiate the platform-specific multi-step media upload process...
```

## The Pivot: Stop Building an Image Processing Farm

Writing Node.js middleware to juggle image buffers, handle smart crops, and manage temporary file storage is a massive distraction. You are building an application, not a cloud-based Photoshop alternative.

Our team at Ayrshare built our infrastructure to abstract this exact headache. When you use our social media image api, you don't need to run sharp on your servers or worry about memory leaks from processing heavy PNGs. We act as your Auto resize images API.

If you send us an image that doesn't fit the strict 1.91:1 OpenGraph ratio or the 4:5 Instagram portrait ratio, our systems intercept it, evaluate the target platform's requirements, and intelligently auto-format the media on the fly. We handle the format conversions, the transparency flattening, and the API delivery in one single sweep.

For more detail, see [LinkedIn media guidelines](/docs/media-guidelines/linkedin).

For more detail, see [Facebook Pages media guidelines](/docs/media-guidelines/facebook_pages).

## The Comparison: Native vs. Ayrshare

Here is what your codebase looks like when you stop wrangling image buffers and let us handle the pixel-pushing.

### Before (Native API + Sharp)

```javascript
// 1. Fetch raw image, load into memory, and run Sharp processing
const imageBuffer = await formatForSocialMedia("https://example.com/raw_image.png");

// 2. Register an upload session with LinkedIn's Assets API
const registerResponse = await axios.post("https://api.linkedin.com/v2/assets?action=registerUpload", { ... });
const uploadUrl = registerResponse.data.value.uploadMechanism["com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest"].uploadUrl;
const assetUrn = registerResponse.data.value.asset;

// 3. Upload the binary buffer to the provided LinkedIn URL
await axios.put(uploadUrl, imageBuffer, { headers: { "Content-Type": "image/jpeg" } });

// 4. Finally, attach the assetUrn to your post payload...
```

### After (Ayrshare API)

```javascript
// We handle the resizing, the smart crop, and the multi-step asset registration.
const ayrshare = require("ayrshare")("YOUR_AYRSHARE_API_KEY");

const response = await ayrshare.post({
  post: "Check out our new dynamic OpenGraph feature!",
  platforms: ["linkedin", "twitter", "facebook"],
  mediaUrls: ["https://example.com/raw_image.png"], // Send the raw file, we fix it.
  profileKeys: ["client_profile_key"]
});

// Done. No Sharp dependencies, no memory limits, no aspect ratio errors.
```

For more detail, see [Instagram media guidelines](/docs/media-guidelines/instagram).

For more detail, see [Cross-Platform API Error 400 (Duration & Metadata)](/solutions/cross-platform-api-error-400-duration-metadata-validation-failed/).

## LinkedIn & Meta Image Dimension Errors: FAQs

### How does Ayrshare fix Invalid Image Dimensions errors on LinkedIn and Meta?

Ayrshare automatically resizes and reformats images to match each platform's required aspect ratio before the request reaches LinkedIn or Meta, which removes the need to run your own image processing middleware.
### What is the correct aspect ratio for a LinkedIn or Meta OpenGraph image?

Ayrshare targets the standard 1.91:1 ratio (1200x627 pixels) that both LinkedIn and Meta expect for OpenGraph link previews, and reformats images that don't already match it.
### Does Ayrshare handle transparent PNG images for social posts?

Ayrshare flattens PNG transparency onto a solid background as part of its media processing, avoiding the black-box rendering that unflattened alpha channels can cause in dark mode.
### Do I need to run my own image processing before sending media to Ayrshare?

No. Ayrshare intercepts each image, evaluates it against the target platform's requirements, and auto-formats it on the fly, so a customer doesn't need a library like Sharp running on their own servers.

## Ship Social Features in Days, Not Quarters

Start your 28-day free trial, or talk with our team about pricing for thousands of profiles.

[Start free trial](https://app.ayrshare.com)
[Talk to sales](/contact/)
