Created
January 27, 2018 09:51
-
-
Save ahadyekta/8803818246f0aefe3a6a3a989a3a7804 to your computer and use it in GitHub Desktop.
Batch convert JPG to WebP in Ubuntu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#First install the webp converter by this | |
sudo apt-get install webp | |
#go inside the directory where all images are there | |
#make sure all images are in RGB color mode, otherwise you will get error for CMYK images. | |
#Convert all images to RGB by this command (you should install ImageMagik to do that) | |
for f in *.jpg; do convert -colorspace RGB "$f" "${f}"; done | |
#finally convert all images to Webp format | |
for f in *.jpg; do cwebp -q 90 "$f" -o "${f}".webp; done | |
#Now you have filename.jpg.webp beside filename.jpg for all your images. | |
#You can set the nginx or other webservers to conditionally show webp instead of jpg if browser support | |
#Read this page to setup it in nginx config : https://github.com/uhop/grunt-tight-sprite/wiki/Recipe:-serve-WebP-with-nginx-conditionally |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for f in *.jpg; do cwebp $f -o ${f%.jpg}.webp; done