1

For example I have a folder called Images and there are 26 folders inside is a,b,c,d contains multiple images each in different format jpg,png,jpeg. How to convert all those images to webp and deleted the originals or else copy converted files to another location with same subfolder name.

1

1 Answer 1

3

Foremost I recommend to install imagick package on your Ubuntu distro.

If you don't have it installed run sudo apt install imagemagick command. Open the folder which you have subfolders containing files with the extensions you want to convert on your terminal.

After that run following command on your terminal:

find . -type f -name "*.png" -exec mogrify -format webp {}  \; -print && find . -type f -name "*.jpg" -exec mogrify -format webp {}  \; -print && find . -type f -name "*.jpeg" -exec mogrify -format webp {}  \; -print

You can also combine all above commands in single expression using regex:

find . -type f -regex ".*\.\(jpg\|jpeg\|png\)" -exec mogrify -format webp {}  \; -print

To remove the leftovers (original files), run following command afterwards:

find . -type f -regex ".*\.\(jpg\|jpeg\|png\)" -exec rm {}  \; -print

For more information about Imagick usage you can find on their official site and about mogrify here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .