[wp-trac] [WordPress Trac] #48194: Unregistered image sizes used for IMG tag "srcset"

WordPress Trac noreply at wordpress.org
Tue Jul 21 05:32:30 UTC 2020


#48194: Unregistered image sizes used for IMG tag "srcset"
--------------------------+------------------------------
 Reporter:  galbaras      |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Media         |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by SherylHohman):

 Replying to [comment:2 joemcgill]:
 > Hi @galbaras. Thanks for reporting this issue.
 >
 > WordPress makes an assumption that if an image size is present in
 attachment metadata, then the file is available to be served to user
 requests and can be included in `srcset` attributes. The best way to clean
 up unused image sizes from the database is to regenerate thumbnails after
 changing themes. You can use a plugin like https://wordpress.org/plugins
 /regenerate-thumbnails/ or the `wp media regenerate` WP-CLI command.
 >
 > Does that help?

 No.
 In my case I do NOT want to regenerate thumbnails.  I want to delete
 generated thumbnails that I will never use.  I have no problem deleting
 them from the server, but I cannot find any plugin or code that will
 enable me to delete references to these thumbnail sizes that no longer
 exist.

 There are goo reasons for wanting to selectively delete auto-generated
 thumbnails.
 1) for some images the auto-generated thumbnails are of *very poor
 quality*. So I manually resize these images and *also* upload them to the
 server.  But when I do so, WP also generates all the same registered sizes
 for every one of these copies too. So now I have a new original for every
 size I want, and yet another poorly resized copy for each.
 In such cases, I delete the generated sizes of the original full size, for
 each size that I am uploading a custom resized version.  And then I delete
 all thumbs for the custom resized versions.
 But all these thumbnail sizes and copies are still listed in the db.
 Which is confusing.  It makes it difficult to find and select the correct
 version of an image I want to use.  And it means I too easily can choose a
 url (for an image) that does not exist.
 And it is very messy to see registered thumbs for non-existent thumbs.

 2) There are many images for which I will NEVER use most of the generated
 sizes. Many images can only be used for specific uses. Many sizes are not
 appropriate for all images.  For example a shopping cart may generate a
 size it needs.  That is great for products.  But for non-products, they
 will never be needed.
 Or specifically designed ultra-wide-very-short images that work for a
 header, or slider, or for an ad.  But can never be used anywhere else - in
 fact many generated thumbs may crop these to produce unusable pics anyway.

 I use a plugin that shows the generated thumb sizes next to every media
 library entry. From there I can easily grab the correct url for the size
 image I want. But after deleting bogus thumbs, all sizes that originally
 generated and registered still show up in the list. Not only is it
 unnecessarily cluttered, but it shows me that there is a ton on stale info
 in the database that has zero way of being cleared/cleaned up.

 I have tried many plugins, and looked at WP-CLI. There are methods
 available to delete ALL thumbnails (which could *also* delete non-
 thumbnails when the user unwittingly happened to name their orig image
 similar to the way WordPress names its resized copies).
 But there is NO way to selectively delete thumbnail sizes for specific
 images.
 Nor is there any way to clean the database if I manually delete thumbs
 from the server.

 There is a way to check for orphaned *original* images, and clean those
 references from the database.
 But that is as close as it gets. And that is to say, useless here.

 We should have a way remove dead references to any image that does not
 exist, whether it is a full size image, or a thumbnail.  The former
 exists. The latter does not.

 Here, I very specifically do NOT want to regenerate these images.

 Can anyone point me to WordPress code that can enlighten me on how to
 remove database references to non-existent thumbnail images?  This should
 work whether the thumb size is *currently* a registered size, or if it is
 *not* currently a registered size.

 Or a way to selectively delete thumbs, through WP Media Library, (without
 forcing regeneration), (or any plugin or command line option) so it *also*
 cleans the DB references to the deleted images?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48194#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list