-
-
Save nickhsu/d3578950164c4c2b8ef290d370c401fa to your computer and use it in GitHub Desktop.
Script to convert all the `JPEG` images to the `WEBP` format in your Android project
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
#/bin/sh | |
# Inpiration: http://engineeringblog.yelp.com/2016/05/yelp-android-app-went-on-a-diet.html | |
# `-lossless` not used to give support for Android 4.0+ | |
# Make sure cwebp is installed. | |
if ! type "cwebp" > /dev/null; then | |
echo "Please install cwebp to continue:" | |
echo "brew install webp" | |
exit 1 | |
fi | |
# Convert all the images in the project that are not converted. | |
for f in $(find . -name "*.jpg") | |
do | |
echo "Converting $f" | |
oldSize=$(du -h $f) | |
cwebp -lossless -mt -jpeg_like $f -o "${f/%.jpg/.webp}" &>/dev/null | |
newSize=$(du -h ${f/%.jpg/.webp}) | |
echo "The image was compressed: $oldSize -> $newSize" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment