Make WordPress Core

Opened 8 years ago

Last modified 4 years ago

#36239 new defect (bug)

wp-embed image size is using the smallest image or it sometimes uses the one for featured images

Reported by: carasmo's profile carasmo Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.4.2
Component: Embeds Keywords: has-patch 2nd-opinion
Focuses: Cc:


When using the wp-embed in my custom post types the image size is correct, a bit big, but it's not blurry. In regular posts, the image size is the thumbnail size created for the media library thumbnail (not the one in the media settings) because that happens to be the smallest one. I noticed that for posts, whatever is the smallest image is being used, whether set in the functions file or by WordPress.

Attachments (1)

36239.diff (801 bytes) - added by desrosj 4 years ago.

Download all attachments as: .zip

Change History (6)

#1 @swissspidy
8 years ago

#36283 was marked as a duplicate.

#2 @swissspidy
8 years ago

  • Keywords reporter-feedback added

Hey @carasmo,

Welcome to WordPress Trac and thanks for creating this ticket. Sorry for not having received a reply in quite a while.

Could you tell us which image dimensions are configured under Settings -> Media? Also, could you perhaps upload an example image this bug happens with?

It would help a lot reproducing this issue.


#3 @carasmo
8 years ago

I fixed this with the filter 'embed_thumbnail_image_size'. If I recall, I was keeping the image sizes generated by media to very teeny and using them as the img src and and a larger version was used as a data-src. My dimensions for the small version were the same ratio as the large versions shown. However, even though my case is unique, many people have blurry images since their image size for the ratio is sometimes smaller. I don't think many will discover this.

#4 @swissspidy
8 years ago

  • Keywords reporter-feedback removed

4 years ago

#5 @desrosj
4 years ago

  • Keywords has-patch 2nd-opinion added
  • Milestone set to Awaiting Review

I was keeping the image sizes generated by media to very teeny

I think this would be OK to close out as being caused by a weird configuration of image sizes.

Looking at the underlying code, we could enforce a minimum dimension check for the login within embed-content.php. The foreach loop there iterates through each generated image size for the specified thumbnail, but it only checks that the height is greater than 0 and that the aspect ratio is greater than 1 (or greater than the last image size that passed the conditional).

As far as I can tell, image meta data is not sorted into any specific order before it's saved in meta. It's based mostly of the order the image sizes are registered/stored in the $_wp_additional_image_sizes global, or when missing sub-sizes are back-filled (after 5.3). So there's no guarantee the last matched image size is the largest, or even large enough to be worth displaying.

36239.diff enforces a minimum width/height requirement of 150px (the default for the Core thumbnail size) to prevent an image that's "too small" from showing. I debated using 300 as the base, but that could potentially limit the number of posts that show an image within an embed.

Note: See TracTickets for help on using tickets.