[wp-trac] [WordPress Trac] #17626: image_get_intermediate_size() may return wrong thumbnail size

WordPress Trac wp-trac at lists.automattic.com
Tue May 31 17:11:48 UTC 2011


#17626: image_get_intermediate_size() may return wrong thumbnail size
-------------------------------------+------------------------------
 Reporter:  chipbennett              |       Owner:
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  Awaiting Review
Component:  Media                    |     Version:
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |
-------------------------------------+------------------------------

Comment (by chipbennett):

 I'm trying to work out the best way to cover the remaining edge case. For
 example, two image sizes have the same width, but different heights. In
 this case, the image size with the smaller height will return, even if the
 image size with the larger height has a height that is smaller than the
 height specified in the `$size` array.

 My thinking is that, if `$imagedata['sizes']` can be sorted from high to
 low on the variable dimension, before looping through the sizes, then the
 ''largest'', rather than ''smallest'', image would be returned.

 Would a function like this work, prior to looping through the images?
 {{{
 // sort $imagemeta['sizes'] descending by width, height
 function compare_sizes( $a, $b ) {
         $sorted = strnatcmp( $a['width'], $b['width'] );
         if( ! $sorted ) return strnatcmp( $a['height'], $b['height'] );
         array_reverse( $sorted );
         return $sorted;
 }
 usort( $imagedata['sizes'], 'compare_sizes' );
 }}}

 (I'm a bit out of my depth on this one, with sorting associative arrays.
 If there's a better way to do this, I'm all ears.)

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/17626#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list