Marketing API Version

Image Crops

Related Topics

Image crops are used to describe the way that an image should be displayed in each aspect ratio of the different ad placements. During rendering, the image will be cropped according to the specifications given, and if no specification is provided for a certain aspect ratio, the image will be displayed in the default way.

Cropping information is optional for all ads, but if cropping is specified, it should be specified for all placements that the ad could appear in. For example, if cropping is specified for Right Hand Column but the ad is also desired to be displayed in Newsfeed, then cropping should be provided for the Newsfeed placement as well. Right now image crops are only supported for ad creatives that support the image_file or image_hash parameters. Page posts are not supported right now.

Image crops are comprised of key-value pairs, where the key is a crop key and the value is the pixel dimensions of the crop, specified as a set of (x, y) coordinates of the upper-left and bottom-right corners of the crop rectangle. A crop key describes an aspect ratio.

The list of keys accepted can be found with Ads Image Crops reference doc.

Values are specified as a two-dimensional JSON array, or an array of two (x, y) tuples. The aspect ratio of the box specified (width/height) must be as close as possible to the aspect ratio of the corresponding crop key.

For cropping, the origin of the image (0, 0) is at the upper-left corner, and the point (width - 1, height - 1) is at the bottom-right corner.

Values must adhere to the following constraints:

  • Points specified by (x, y) must lie within the image. A rectangle that extends beyond the bounds of the image is considered invalid.
  • The rectangle must be the same aspect ratio as specified by the crop key.
  • Coordinates must not contain negative values.


   "191x100": [ [100, 10], [433, 184] ],
   "100x72": [ [160, 20], [371, 172] ]


First, upload the ad image that you will use in your ad creative:

use FacebookAds\Object\AdImage;
use FacebookAds\Object\Fields\AdImageFields;

$image = new AdImage(null, 'act_<AD_ACCOUNT_ID>');
$image->{AdImageFields::FILENAME} = '<IMAGE_PATH>';

echo 'Image Hash: '.$image->{AdImageFields::HASH}.PHP_EOL;
from facebookads.adobjects.adimage import AdImage

image = AdImage(parent_id='act_<AD_ACCOUNT_ID>')
image[AdImage.Field.filename] = '<IMAGE_PATH>'

# Output image Hash
AdImage adImage = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdImage()
  .addUploadFile("filename", new File(<IMAGE_PATH>))
curl \
  -F 'filename=@<IMAGE_PATH>' \
  -F 'access_token=<ACCESS_TOKEN>' \<AD_ACCOUNT_ID>/adimages

Then, create an ad creative by referencing the image hash returned in the previous call:

use FacebookAds\Object\AdCreative;
use FacebookAds\Object\Fields\AdCreativeFields;

$creative = new AdCreative(null, 'act_<AD_ACCOUNT_ID>');
  AdCreativeFields::OBJECT_URL => '<URL>',
  AdCreativeFields::TITLE => 'My Title',
  AdCreativeFields::BODY => 'My Ad Body',
  AdCreativeFields::IMAGE_HASH => '<IMAGE_HASH>',
  AdCreativeFields::IMAGE_CROPS => array(
      '191x100' => array(
        array(100, 10),
        array(433, 184),
      '100x72' => array(
        array(160, 20),
        array(371, 172),

from facebookads.adobjects.adcreative import AdCreative

creative = AdCreative(parent_id='act_<AD_ACCOUNT_ID>')
creative[AdCreative.Field.object_url] = '<URL>'
creative[AdCreative.Field.title] = 'My Title'
creative[AdCreative.Field.body] = 'My Ad Body'
creative[AdCreative.Field.image_hash] = image_hash
creative[AdCreative.Field.image_crops] = {
    '191x100': [
        [100, 10],
        [433, 184],
    '100x72': [
        [160, 20],
        [371, 172],

curl \
  -F 'object_url=<URL>' \
  -F 'title=My Title' \
  -F 'body=My Ad Body' \
  -F 'image_hash=<IMAGE_HASH>' \
  -F 'image_crops={"191x100":[[100,10],[433,184]],"100x72":[[160,20],[371,172]]}' \
  -F 'access_token=<ACCESS_TOKEN>' \<AD_ACCOUNT_ID>/adcreatives