Search code examples
linuxubuntuterminalcompressionwebp

Converting jpg, jpeg, png to webp in Linux Command Line


After running:

$ sudo apt-get install webp

I ran the following script:

$ for file in *.jpg *.jpeg *.png; do cwebp "$file" -o "${file%.*}.webp"; cp --preserve=mode "$file" "${file%.*}.webp"; done

All files within the current directory were converted to webp, however, the size was exactly the same. It was as if it didn't actually compress the file and instead just changed the ending.


Solution

  • cp --preserve=mode "$file" "${file%.*}.webp"; 
    

    Why do you need the "cp" line? It's just copying the jpeg/png to the webp file from the previous command and that's why you're seeing no change in file size.