[wp-trac] [WordPress Trac] #34384: No way of preventing image_get_intermediate_size from returning cropped image

WordPress Trac noreply at wordpress.org
Thu Dec 10 16:58:07 UTC 2015


#34384: No way of preventing image_get_intermediate_size from returning cropped
image
------------------------------------+------------------------------
 Reporter:  pputzer                 |       Owner:
     Type:  defect (bug)            |      Status:  new
 Priority:  normal                  |   Milestone:  Awaiting Review
Component:  Media                   |     Version:  3.0
 Severity:  normal                  |  Resolution:
 Keywords:  has-patch dev-feedback  |     Focuses:
------------------------------------+------------------------------
Changes (by flixos90):

 * keywords:   => has-patch dev-feedback


Comment:

 Replying to [ticket:34384 pputzer]:
 > I'm not sure why @markjaquith implemented things this way in [13145],
 but I assume changing them completely will break something somewhere, so
 the new parameter might be the better solution for backwards
 compatibility.

 [attachment:34384.diff] is a take on the approach you suggested, using a
 new parameter to disable the behavior. Not sure about the naming
 conventions there, but it should basically allow to bypass the thumbnail
 image in the case you described.

 However, there is something else in that function that struck me: The
 `image_resize_dimensions()` call is returning a non-cropped version of the
 original image which fits into the size we're iterating through in the
 array. Why is that? I feel like it should take the resized version of the
 image and resize it into the `$size` we're requesting to get.

 To be more precise, in my opinion this
 {{{#!php
 <?php
 $maybe_cropped = image_resize_dimensions($imagedata['width'],
 $imagedata['height'], $data['width'], $data['height'], false );
 }}}
 should become
 {{{#!php
 <?php
 $maybe_cropped = image_resize_dimensions($data['width'], $data['height'],
 $size[0], $size[1], false );
 }}}
 and we would also need to adjust the comparison afterwards accordingly.

 The problem the current version produces for the user is the following:
 Let's say, for example, you upload an image of 1200x800 (with ID 2) and
 you have a 300x500 image size with hard crop registered. And now you call
 `image_get_intermediate_size( 2, array( 60, 100 ) )`. First of all, this
 would be another example of a case where we would need to disable the
 thumbnail workaround (the cause of the original issue). But even if we did
 that, we would get a wrong image back - it would probably return the
 medium size since it has the same aspect ratio as the original image (but
 that depends on the image sizes we have on the site). In this case
 however, this wouldn't make any sense since we actually have an image that
 is the aspect ratio we want.

 Correct me if I'm wrong about what the function does, but if I'm not, we
 should probably deal with the above in a separate issue. I first wanted to
 make sure it's valid before opening one.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/34384#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list