spacecatninja / craft-imager-x

Image transforms, optimizations and manipulations for your Craft CMS site.
Other
26 stars 16 forks source link

Clear resized images on asset replace - good idea? #277

Open hiasl opened 3 days ago

hiasl commented 3 days ago

I'm submitting a...

Steps to reproduce

Our editors just complained that when they do a "Assets > any image > replace file" with another asset with the same filename, the resized images do not get regenerated. I checked that and they are right, since the default transformation string does not respect a file's mtime.

So we now modify it in a config/imager-x.php to

'filenamePattern' => '{basename}_{transformString|hash}_{timestamp}.{extension}'

This does the job, but I was wondering if it is generally a good idea to keep resized images when the content of the file changes (or in other words, when someone replaces the file with a different binary). My initial idea would be to simply delete the folder which is named by the assets's ID in the resized image path, that would automatically clear all resized images of the replaced image binary.

My thoughts:

What are your thoughts on this?

aelvan commented 3 days ago

Hi,

The Imager cache is actually supposed to be deleted when a file is replaced, so I'll have to check if there's a bug there if that wasn't happening for you. But, what OS is this on (or, where did you test and confirm that it was not deleted), and you're using the local "craft" transformer right?

hiasl commented 1 day ago

Hi, yes, we are transforming locally!

This is the setup where I tested: PHP version 8.2.13 OS version Linux 4.18.0-553.22.1.el8_10.x86_64 Database driver & version PostgreSQL 12.18 Image driver & version GD 8.2.13 Craft edition & version Craft Pro 4.13.1.1 Blitz 4.23.7 Imager X 4.4.1

I did the following:

one more note: Both the source and the resized images are on an NFS share. To make sure, file permission are not the root of this problem, I su'ed into the user of the webserver and tried to delete such a directory on the console, this worked.