[wp-trac] [WordPress Trac] #22738: 3.5 Media: Correct display of dimensions for large-size images in size dropdown

WordPress Trac noreply at wordpress.org
Tue Dec 4 18:37:36 UTC 2012


#22738: 3.5 Media: Correct display of dimensions for large-size images in size
dropdown
-----------------------------+--------------------------
 Reporter:  jond3r           |       Type:  defect (bug)
   Status:  new              |   Priority:  normal
Milestone:  Awaiting Review  |  Component:  Media
  Version:  trunk            |   Severity:  normal
 Keywords:  has-patch        |
-----------------------------+--------------------------
 To better comply with the behavior in WP 3.4 here is a proposed small fix
 for computing the dimensions shown in the image size drop-down box in the
 "Media modal" when inserting images from the media library.

 This applies mostly to large-size images, which generally are constrained
 in size by the global variable $content_width set by the theme. For
 example TwentyTwelve sets $content_width = 625. When an image that is
 wider than $content_width is inserted, it is "constrained" in size to the
 value of $content_width, that is its width and height attributes
 ("hwstring") are adjusted.

 In 3.4 the constrained dimensions are shown in the dropdown when an image
 is inserted, in the current 3.5 trunk the unconstrained dimensions are
 shown, e.g. Large is generally shown to have a width of 1024, whereas in
 3.4 it is shown as 625 (for TwentyTwelve). The code inserted in the editor
 is however the same for both versions.

 (As a side note, the image class gets a value of "size-large" even though
 the size attributes are constrained. But this is a "legacy" behavior.)

 The proposed fix makes a call to image_constrain_size_for_editor() in
 wp_prepare_attachment_for_js() (file wp-includes/media.php).
 Referring to #22598 there was a worry that repeatedly calling
 image_downsize() would be too slow. However, it is sufficient in this case
 to call image_constrain_size_for_editor(), and just for large-size (or
 custom) images. (The only drawback i found was that the filter
 'editor_max_image_size' will not be applied for thumbnails and medium
 images if these are bypassed image_constrain_size_for_editor()).

 I also added a small performance improvement to wp_constrain_dimensions(),
 which now returns immediately if the current and max dimensions are equal.

 The attached image shows the image size dropdown before and after the fix,
 which also complies with 3.4.

 (This was a long description to a small fix, phew.)

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22738>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list