Image resizing from crop coordinates

So I’m currently using Amazon Lambda processing images with Thumbor for image resizing / cropping needs. I really want to move to CF Image Resizing, but I’m not finding in the documentation how to crop as I need.

My images have crop data stored as an x/y coordinate with a height and width – so the crop area is defined, and then resizing is done off that.

Cloudinary also had this type of crop defining available, and I’m surprised to see it missing here. So I guess my question is - have I overlooked or misunderstood how to do this?

Thanks for any replies!

You are on a Business plan, right?

The URL based resizing does not seem to support specifying x and y. Workers however appear to do so via the gravity field.

Even with using gravity, I don’t think it can achieve the same result.

To me it seems this is exactly what you are looking for, isn’t it?

When cropping with fit: "cover" and fit: "crop" , this defines the side or point that should be left uncropped. The value is either a string "left" , "right" , "top" , "bottom" or "center" (the default), or an object {x, y} containing focal point coordinates in the original image expressed as fractions ranging from 0.0 (top or left) to 1.0 (bottom or right), 0.5 being the center. {fit: "cover", gravity: "top"} will crop bottom or left and right sides as necessary, but won’t crop anything from the top. {fit: "cover", gravity: {x:0.5, y:0.2}} will crop each side to preserve as much as possible around a point at 20% of the height of the source image.

Maybe a real life example will help. On the left is the original image. On the right is the result of the crop. The image is 720 x 480. The crop area is defined by
98,62 (x,y) and 365,418 (width, height).

So I’d calculate the gravity point as
1 - ((x+1/2 crop width) / image width) – 1- (98+(364/2) / 720)) =~ .359
1 -((y+1/2 crop height) / image height) – 1 - ((62+(418/2) / 480)) =~ .435

And… I have to run to a meeting and i don’t see a safe draft anywhere.

Sandro, thank you for your assistance thus far. I’ll give you a shout out if I get it.

I have never used image resizing on Cloudflare and only know the theory, but from the description of gravity it would seem as that is exactly what you’d do to achieve the example you posted.

I’ve heard from our CF representative that this isn’t supported.

I would really love to see this added.

What did you get when you tried gravity?

Just ran a couple of tests. I am not sure gravity is so much the issue, rather fit.

fit: "crop" does not seem to really crop.


Can you please try the new “trim” option in Workers?


An object with four properties {left, top, right, bottom} that specify a number of pixels to cut off on each side. Allows removal of borders or cutting out a specific fragment of an image. Trimming is performed before resizing or rotation. Takes dpr into account.

Thank you