• I’ve noticed that, after uploading an image, WordPress, correctly, creates all the thumbnail needed. Unfortunately, when I resize the image, it creates a new image as well as all the new thumbnails again.

    To save space, I would like to delete the original image as well as all the thumbnails previously created with the original image, in the case I’m going to resize the image.

    Is it possible?

    • This topic was modified 5 years, 1 month ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not a Developing with WordPress topic
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @nicocaldo,

    WordPress has an option to delete unused media. Go to Media – Library. Locate the drop-down menu with the label All media items, select the unattached media option and WordPress will show you media not attached to any post/page. You can delete them to free up space. I’ll recommend backing up your site first, so if things don’t work as expected you can revert. Cheers.

    Thread Starter nicocaldo

    (@nicocaldo)

    The problem is that it doesn’t discriminate against the resize and the original image.

    If the image has been attached to a post and it has been resized, they both are attached on the post even if the resized one is the only actually used

    I think I understand better what you mean. The images are resized for display on different device sizes, e.g mobile, desktop, tablet. They’re not duplicate images and is necessary to serve images that fits on different devices and different locations of your site.

    To disable this go to media settings and change the thumbnail sizes to 0. That’s, navigate to Settings – Media and change the values to 0.

    Thread Starter nicocaldo

    (@nicocaldo)

    I’m talking about the image that I manually resize to save space.

    My theme uses image sizes smaller than 1024×1024 so, I usually resize the bigger image down to 1024.

    Unfortunately, when I do that, it creates a brand new set of images, thumbnails included.

    If I check the upload folder I can find the original size image, with all the resize thumbnail produced by WordPress and the image resized manually by me with, again, all the thumbnail

    Usually the manually resized images have a string added at the end of the file name in the form of -efilename.jpg

    For instance, if I upload an image called myimage.jpg and I manually resize it via the WordPress media manager, it creates another image inside the upload folder called myimag-emyimage.jpg

    Having both is useless and I’m try to find out how to delete the original one with its thumbnails

    Moderator bcworkz

    (@bcworkz)

    You would need to hook an action or filter that fires after a resized image is saved, determine the original attachment, then delete (unlink() in PHP) the related files. One possibility is to hook the “update_postmeta” action and look for updates of the key “_wp_attachment_backup_sizes” which is used when wp_save_image() executes. This function is called for any image save, so your code would need to differentiate resize saves from other saves before deleting any files. Completely untested approach, but it’s what I would try first.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Delete original images after resize’ is closed to new replies.