3

Before we start, the image is definitely big enough.

I have an image that is 2206 x 2042 and I wish to crop (not scale) it in a number of different ways to be used responsively.

The sizes I am trying to produce are:

add_image_size( 'artist-full-xs', 730, 1842, array('right', 'bottom') );
add_image_size( 'artist-full-xs-sm', 730, 1000, array('right', 'bottom') );
add_image_size( 'artist-full-xs-sm-2', 730, 600, array('right', 'bottom') );

The first image crops as it is supposed to, the next two both scale instead of crop. This is found by looking in the uploads folder, nothing to do with any templating issues.

@Andy Macauley-Brook Actual sizes output are as follows:

730 x 1842 730 X 1000 730 X 600 So the actual cropping is working is just working proportionally for the last two instead of an actual crop

Does anyone know why and can possibly help me out?

  • What are the actual sizes that the three images end up as? – Andy Macaulay-Brook Jun 12 '16 at 16:34
  • 1
    Please try to use same account, that will allow you to properly edit and discuss your own question. If you didn't mean to create multiple accounts you can request to merge them wordpress.stackexchange.com/help/merging-accounts – Rarst Jun 12 '16 at 17:09
8

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

| improve this answer | |
  • I thought you could add a filter to image_resize_dimensions to bypass the scaling that WP does and get a real crop? – cjbj Jun 12 '16 at 17:40
  • Yes, that's possible. Would have to math coordinates stuff on your own though. :) Also I am not sure that's really desirable in many cases. Smaller "real" crop out of large image can be pretty nonsensical. – Rarst Jun 12 '16 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.