Download & Extend

Remove old resized images when creating new one

Project:Image Resize Filter
Version:6.x-1.8
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

When I resize the image via wysiwyg, filter creates the file with resized image.
But when I try to edit this node and resize the image again, filter creates the new file, but didn't delete old one.
And after many tries to find optimal image size, I will see many resized files of this image, but for displaying node I needs only one of it, with current image size.
Can this module scan the folder and remove old files with sized don't used at now by node?

Comments

#1

Thanks for the suggestion. I think this would be a good enhancement, though the logic to do this in an efficient manner might be a slightly tricky thing to accomplish.

#2

For example, we can remember current size of image when loading node edit form, and after that check - if changed, remove old.
Or more easily - always remove thumbnails for image when editing node and recreate on node save.

#3

Another method is like in imagecache - parse urls, contains "resized" part, and recreate the file automatically on access request (if file is missed).
If you do this, you can bravely remove all resized versions of image and don't matter that delete more than needed.
And you can cleanup all folder periodically via cron, all needed files will be recreated on access request.

#4

Both of these suggestions introduce some problems:

For example, we can remember current size of image when loading node edit form, and after that check - if changed, remove old.
Or more easily - always remove thumbnails for image when editing node and recreate on node save.

There is no guarantee that some image is not in use in multiple places, so we can't just delete the previously used images.

Another method is like in imagecache - parse urls, contains "resized" part, and recreate the file automatically on access request (if file is missed).

This approach seems like it would be safe but it would cause a greater performance penalty regenerating these images on view instead of on creation. It would also require Clean URLs as ImageCache does.

My feeling generally is that disk space is cheap and we don't really need to worry about this too much. The majority of sites will take performance and reliability over disk space any day. And if the original node or file is ever deleted, Image Resize Filter is good enough about clean up that it will delete derivatives of an image if the original is deleted.

#5

Very often users edits one node 100 times when trying to find optimal image size. And Image Resize Filter creates 100 copies of original image on this process, that is not good.

The method like in imagecache parse the php script only when thumbnail is not created, if file is already exists (via rules in .htaccess) - it directly load the image without loading Drupal core and php scripts. And we got performance issue only one time on first node load if some images will be missed.

And Clean URLs works in most of servers.

#6

Generally, I would like the option to flush and/or recreate image_resize images in a manner similar to imagecache. The procedure would be to go through all nodes, blocks, comments, etc., looking for image tags and recreating if needed. I can see this would be tricky, because there are so many places where filters are applied to fields.

One way to deal with the issue would be to have the filter keep a tally in the database of all the places it's been applied. If someone subsequently edits the same field and removes the image, the filter would notice this and subtract one from the image's use-count. If the use-count goes to zero the image is either deleted or archived.

Of course, another way to deal with it would be to have image_resize do the resize magic in the same manner as imagecache - at the time the image is requested by the user's browser. Just a thought.

With the prevalence of WYSIWYG editors, it would be a really cool thing generally to have automatic tracking for inline images, so that more modules could be made to take advantage of it. If I get a chance I'll experiment with making an "asset tracking" filter as a separate project, or if anyone reading this thread is interested in following it up, I know it would be a huge value-added Drupal feature!

#7

You can already delete all the resized images at any time and Image Resize Filter will automatically recreate them. Image Resize Filter isn't "on demand" like ImageCache, instead it generates images when it reads the HTML and determines that resized images are necessary. The only thing you need to watch out for is that you clear your filter cache if you delete all the images. Image Resize Filter actually already provides an API function for doing this exact thing. There's no exposed option in the UI because generally I don't think disk space is an issue on the majority of sites.

#8

Maybe adding a button that clears the filter cache and deletes all files in the resize folder, accompanied with an explanation that the /resize folder can be emptied at any time without fear for loss of data because any required images that do not exist will be created on the fly would solve this issue?!

#9

I was surprised to find a folder called /resize/resize

This directory does not normally exist, it was caused by the WYSIWYG editor resizing images twice (same as #983800: Resizing twice causes needless loss of quality).

The resize directory never contains any originals. You can delete the entire directory at any time, like I said in #7.

#10

I tried out your demo, which under Drupal 7. Same issue. Old resized images are not removed. When you delete the original, the resized copy should be removed. We don't want garbage on our machines and it has also a privacy issue. When a user really wants to remove all traces of an images all (resized) copies should be removed with it.

nobody click here