Make WordPress Core

Opened 5 years ago

Last modified 8 months ago

#48489 new defect (bug)

Big image size threshold should take into account registered image sizes.

Reported by: johnbillion's profile johnbillion Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 5.3
Component: Media Keywords: good-first-bug has-patch needs-unit-tests
Focuses: Cc:

Description

The "big image" upper size threshold is set to 2560. If an image size is registered that has a width or height larger than this, then the image will be unexpectedly cropped to 2560.

The value that gets passed through to the big_image_size_threshold filter should be set to the maximum value of either 2560 or the largest width or height from all registered image sizes.

Attachments (2)

48489.diff (1.9 KB) - added by psrpinto 3 years ago.
48489.2.diff (3.9 KB) - added by f26d 8 months ago.

Download all attachments as: .zip

Change History (13)

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


5 years ago

#2 @pbiron
5 years ago

  • Milestone changed from Future Release to 5.4

#3 @johnbillion
4 years ago

  • Focuses performance removed
  • Keywords needs-patch added; dev-feedback removed

#4 @johnbillion
4 years ago

  • Milestone changed from 5.4 to Future Release

#5 @johnbillion
3 years ago

  • Keywords good-first-bug added

@psrpinto
3 years ago

#6 @psrpinto
3 years ago

I submitted a patch which implements the solution suggested in the ticket description:

The value that gets passed through to the big_image_size_threshold filter should be set to the maximum value of either 2560 or the largest width or height from all registered image sizes.

However, I noticed that many of the default themes (e.g. twentytwentyone, twentytwenty, twentynineteen) set the post_thumbnail_size's height to 9999, which results in the threshold now being 9999.

This means the majority of pictures will not be cropped, and I'm not sure that was the intention behind the proposed solution.

Do you think such a high threshold makes sense @johnbillion?

#7 @karpstrucking
3 years ago

  • Keywords has-patch added; needs-patch removed

#8 @adamsilverstein
13 months ago

  • Keywords needs-unit-tests added

However, I noticed that many of the default themes (e.g. twentytwentyone, twentytwenty, twentynineteen) set the post_thumbnail_size's height to 9999, which results in the threshold now being 9999.

@psrpinto Do we know why these themes use that value? I assume the goal is to crop only the horizontal dimension? is there another way to achieve that?

or maybe we can separate out the width/height treatment, or treat 9999 as a special case?

#9 @a4jp.com
12 months ago

I never knew that all images had a maximum size of 2560 when getting cropped T-T. This should be explained in /wp-admin/options-media.php if it's a set limit we can't change.

Would it make sense to allow a blank field to work if we don't want the height cropped instead of having to type 9999? I'd rather leave the field empty with nothing in it if I didn't want anything cropped instead of typing in a weird number like 9999. 9999 should crop at 9999 if images that big exist though (codewise).

This ticket was mentioned in Slack in #core-test by danieldayton33. View the logs.


11 months ago

@f26d
8 months ago

#11 @f26d
8 months ago

The 9999 height hack for the post-thumbnail size does complicate things… I think it makes sense to loop over just the widths of the image sizes to potentially bump up $threshold.

There doesn't seem to be a perfect solution to this, but in general (*waves hand*), it seems more common to resize images based on a width constraint than based on a height constraint. This makes me think that plenty of custom image sizes are likely to use identical width and height (or something like 9999 for the height, so that the height argument is essentially disregarded).

I've updated @psrpinto's diff with this suggested approach, as well as with some unit tests.

This is my first contribution to core, so please let me know if I'm missing something!

Note: See TracTickets for help on using tickets.