spacecatninja / craft-imager-x

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

Safe deletion of transforms older than x days #269

Closed romainpoirier closed 4 months ago

romainpoirier commented 5 months ago
### I'm submitting a...

Description

I have a website that generates numerous personalized images for each visitor. The number of Imager transformations becomes very large and overloads the server's disk space. Using a cron job, I delete Imager files that are x days old to keep at least those of users currently using the site. This involves processing image files in `/htdocs/imager/`, and also in `/www/storage/runtime/imager`/ which contains PHP files. Can I safely delete PHP files in `/www/storage/runtime/imager/` that are also x days old? Or could this cause errors if the index and date management are not the same as for the images in `/htdocs/imager/`? ### Additional info - Imager version & edition: 4.4.0 - Imager transformer: Pro - Craft version: 4.8.9 - PHP version: 8.1.24 - Image driver & version: Imagick 3.7.0 (ImageMagick 6.9.12-93)
aelvan commented 4 months ago

Hi,

The files in @runtime/imager shouldn't be needed anymore, if the reason why the file was created, resulted in a successful transform being generated. Imager will check if the resulting transform exists in the imagerSystemPath, and if it does, it'll not need anything stored in @runtime/imager.

In general, there're two scenarios where Imager would need to create a temporary file there; 1) you're transforming external images (or passing in assets by URL, which you shouldn't do), or 2) you use a custom encoder like cwebp or cavif to deliver formats not supported by your image driver. In both cases, if Imager successfully makes the final transform (in your imagerSystemPath), the temporary file is no longer needed. If you set cacheRemoteFiles to false, files will be deleted at the end of the session in scenario 1, and file should always be automatically deleted in scenario 2.

So, sounds like you'd want to set cacheRemoteFiles to false, and if you still have files lingering in the runtime folder, something's not right. Let me know if that's the case. 🙂