sh 在Android项目中将所有`JPEG`图像转换为`WEBP`格式的脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 在Android项目中将所有`JPEG`图像转换为`WEBP`格式的脚本相关的知识,希望对你有一定的参考价值。

#/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

以上是关于sh 在Android项目中将所有`JPEG`图像转换为`WEBP`格式的脚本的主要内容,如果未能解决你的问题,请参考以下文章