WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 7 months ago

#34225 new defect (bug)

Display correct dimensions for image sizes in media modal

Reported by: krogsgard Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.3.1
Component: Media Keywords: has-patch
Focuses: administration Cc:

Description

In the media modal dropdown, the available image sizes and their dimensions are shown like this:

https://cldup.com/fO5zZgC7OV.png

But the image dimensions are actually larger. The shown values are restricted because of the theme's $content_width variable. The actual values are like this:

https://cldup.com/DHFDDrEnlb.png

This dropdown is for informational purposes only, and the actual image size should show, not the constrained dimensions that will be in the media markup (largely for TinyMCE / editor purposes I believe).

These image sizes are output to this modal template from wp-includes/media-template.php, and that data is setup from wp_prepare_attachment_for_js.

This function calls the image_constrain_size_for_editor, which has a fourth parameter for context. That parameter is set to be edit both here and by default, and therefore the image constraints are set to this dropdown, even though it is for informational purposes only.

Current contexts documented currently are edit or display. edit is the default if is_admin() returns true. There should be a third context, that does no constrain the image size, if the purpose for grabbing the image size is for informational purposes. Therefore, I think the best solution is to allow for a new context that I'm calling info.

The new context would override the admin context, but not override the width parameter on the inserted media (that's useful for editor/TinyMCE purposes), nor would it override anything on the front end. It just edits it for reference purposes in the dropdown, to prevent innaccurate information from being presented to the user.

Attachments (1)

34225.diff (1.7 KB) - added by krogsgard 2 years ago.
add info context, clean up curly brackets, and check context for large images

Download all attachments as: .zip

Change History (6)

#1 @krogsgard
2 years ago

I just completely borked the diff. fixing soon but if anyone wants to delete the current that works for me :)

@krogsgard
2 years ago

add info context, clean up curly brackets, and check context for large images

#2 @mikeschroder
2 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to Future Release
  • Summary changed from Add context to image_constrain_size_for_editor for media modal dropdown, to show proper image size dimensions to Display correct dimensions for image sizes in media modal

#3 @joemcgill
19 months ago

Related: #35390. If we removed image_constrain_size_for_editor() from the image_downsize() dependency chain, we could fix this without passing around context. As @azaozz rightly pointed out on #35390, the function name itself includes "for_editor", so trying to figure out context is a bit of an oddity.

That said, I'm not opposed to including a short term fix for this as it does seem unexpected that you would include custom sizes in that dropdown and get a constrained size represented.

This ticket was mentioned in Slack in #core by pressupinc. View the logs.


10 months ago

This ticket was mentioned in Slack in #core-media by joemcgill. View the logs.


7 months ago

Note: See TracTickets for help on using tickets.