yireo / Yireo_Webp2

Magento 2 module to add WebP support to Magento 2
Open Software License 3.0
194 stars 54 forks source link

force regeneration #146

Closed skeutmeier closed 10 months ago

skeutmeier commented 1 year ago

Hi,

What is the advised way to force a regeneration of images, for example if I change the quality settings in the backend?

Thank you

jissereitsma commented 1 year ago

Best way would be - to my opinion - removing the old WebP images, for instance from the shell by using find of some kind. Likewise, you could also just use the CLI command of this module to regenerate the images again.

jissereitsma commented 10 months ago

I'm closing this ticket due to inactivity. Feel free to reopen if needed.

rostilos commented 10 months ago

About the CLI command : it is only available for 1 single picture. In my case it was necessary to regenerate all files, because I wanted to test different quality when converting. Since default setting of the module is "Save in the same directory as the source", I wrote a small script to check if there is a source with the same name next to the .webp picture and delete the .webp in that case (this will help not to delete other .webp pictures that may have been added to the environment as a source, but were not converted). Perhaps someone will find this useful ( In any case, it is advisable to make a backup of the media ) : cd pub/media

find . -type f -name '*.webp' -exec bash -c 'for f; do base="${f%.*}"; source_file_jpg="${base}".jpg;source_file_jpeg="${base}".jpeg;source_file_png="${base}".png; if [ -f "$source_file_jpg" ] || [ -f "$source_file_png" ] || [ -f "$source_file_jpeg" ]; then rm "$f"; echo "$f"; fi; done' bash {} +

jissereitsma commented 10 months ago

Cool option indeed. I'll try to squeeze this somewhere in the docs.