add_image_sizes ignoring crop sizes and using proportion

WordPress “crop” doesn’t literally mean crop. As in take an image and cut out this precise portion of it from specified point.

What it roughly means is: resize image to fit as well as possible, then crop parts that don’t fit. In effect this meant that results are affected by ratio both of source image and target size.

The exact logic is contained in image_resize_dimensions() function and summarize by inline comments as following:

// crop the largest possible portion of the original image that we can size to $dest_w x $dest_h

Not just exact portion, but largest possible portion of original.

The exact steps are math and aren’t too friendly to briefly read and/or explain. From quick look what seems to happen is:

  1. Ratio of original image is calculated.
  2. How would it best fit onto target size is determined.
  3. Crop applied on result of previous step.

In your specific case the difference between sizes is that first two are tall (larger height) and third one is wide (larger width).

  • In former case the original is sized by height, then left part is cut off.
  • In latter case the original is sized by width, then top part is cut off.

That what leads to sizes looking different. Because aspects ratios are different, WP fits original into them in different ways.

If you look at them side by side it’s pretty visible how this logic got applied:

wordpress image sizes crop

Leave a Comment