[wp-trac] [WordPress Trac] #45449: Switched thumbnail scaling + cropping output

WordPress Trac noreply at wordpress.org
Thu Nov 29 18:52:33 UTC 2018


#45449: Switched thumbnail scaling + cropping output
--------------------------+-----------------------------
 Reporter:  sicco         |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:  4.9.8
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 I have added the following to my functions.php in order to create
 thumbnails of 660x250 which are allowed to crop:

     add_image_size( 'square-large-xs-sm', 660, 250, true);

 This works fine for some images, but it gives the wrong result for others.
 E.g., if I add an image of size 2048x1365 it will result in a thumbnail of
 375x250 instead of 660x250. Then if I add an image of 1636x1050 it will
 result in a thumbnail of the correct 660x250 size.

 My theory is that the 1636x1050 can be scaled based on **both** the width
 **and** the height (of course without losing aspect ratio) as you end up
 with an image larger than 660x250 in **both** cases, so you can then just
 crop the remainder from the image. But with the 2048x1365 image just
 **must** scale the **width** to 660 which results in an image of 660x440
 and then the height of 440px is cropped to 250px. If you first scale to a
 height of 250px you'll end up with an image of 375x250, where the width of
 375px is thus already too small compared to the wanted 660px.

 NOTE: as I specified at the start of this post, I actually end up with an
 image of 375x250, so it seems that the wrong scaling is applied to my
 image (based on height instead of width). To make it even more
 interesting. If I add an image that needs to actually be scaled based on
 height instead of width (so the opposite of the case I just described), it
 will end up scaling based on width! So it seems that function tries to
 determine whether to use width or height for scaling, but then ends up
 using the wrong one!

 Am I correct, or am I totally confusing things?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45449>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list