Skip to content

Instantly share code, notes, and snippets.

@SandroMachado
Last active January 13, 2021 01:11
Show Gist options
  • Save SandroMachado/9ee516bbd36768ca3844876c50cf4618 to your computer and use it in GitHub Desktop.
Save SandroMachado/9ee516bbd36768ca3844876c50cf4618 to your computer and use it in GitHub Desktop.
Script to convert all the `JPEG` images to the `WEBP` format in your Android project
#/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 -pass 10 -m 6 -mt -jpeg_like -q 60 $f -o "${f/%.jpg/.webp}" &>/dev/null
newSize=$(du -h ${f/%.jpg/.webp})
echo "The image was compressed: $oldSize -> $newSize"
rm $f
done
@twlkyao
Copy link

twlkyao commented Nov 7, 2018

Is there a way to convert the jpg, png files according to the android api, and the format of png, like is has alpha channel, just like the Android Studio do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment