Make WordPress Core

Opened 4 years ago

Last modified 4 years ago

#50944 new defect (bug)

wp_calculate_image_srcset can unintentionally include unscaled original image

Reported by: fredrikll's profile fredrikll Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.4
Component: Media Keywords: 2nd-opinion
Focuses: Cc:

Description

In wp-includes/media.php, wp_calculate_image_srcset seems to add the original image to the srcset string if the width is smaller than $max_srcset_image_width and if the image isn't a GIF. This isn't desirable since the original image is uncompressed and I don't even think it's intentional.

This behavior seems to have been introduced in this patch: https://core.trac.wordpress.org/changeset/35561. From what I can tell, the if statement should read like this:

if ( ! isset( $image_sizes['thumbnail']['mime-type'] ) || 'image/gif' === $image_sizes['thumbnail']['mime-type'] ) {

The current code will include the original image whenever the thumbnail IS NOT a GIF. This seems to be opposite to the desired behavior?

Change History (6)

#1 @johnbillion
4 years ago

  • Component changed from General to Media
  • Keywords needs-testing added
  • Milestone changed from Awaiting Review to 5.5.1
  • Version changed from trunk to 5.5

Thanks for the report @fredrikll and welcome. Moving this to 5.5.1 for investigation.

#2 @johnbillion
4 years ago

  • Keywords 2nd-opinion added; needs-testing removed

#3 @khag7
4 years ago

To prevent anyone from getting as confused as I did:
Change [35561] is just a refactor and better description. The logic stayed the same.

The change that introduced no srcset on gifs was slightly sooner, in [35524].

#4 @fredrikll
4 years ago

@khag7 the refactor in [35561] actually seems to be the issue. If the relevant if statement would still look like [35524], this bug would be fixed, from what I can tell.

The difference should be quite clear if one looks closer: isset( $image_sizes['thumbnail']['mime-type'] ) && 'image/gif' === $image_sizes['thumbnail']['mime-type'] versus ! isset( $image_sizes['thumbnail']['mime-type'] ) || 'image/gif' !== $image_sizes['thumbnail']['mime-type']

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


4 years ago

#6 @johnbillion
4 years ago

  • Milestone changed from 5.5.1 to Awaiting Review
  • Version changed from 5.5 to 4.4
Note: See TracTickets for help on using tickets.