shell脚本 将非9图和不在黑名单中的png转webp

前端之家收集整理的这篇文章主要介绍了shell脚本 将非9图和不在黑名单中的png转webp前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
# !/bin/bash
# function: convert all png images file (except for ".9.png")in the current directory and subdirectories to webp format
echo "Starting convert images format,please wait a minite..."
con="\.9\.png"
extra=`cat extra`
for var in `find . -name "*.png"`; do
    flag=1
    fileName=${var##*/}
    file=${fileName%%.*}
    for ex in $extra; do
        if [ "$file" = "$ex" ]; then
#            echo find $ex = $file
            flag=0
            break
        fi
    done
    if [ "$flag" -eq 0 ]; then
     	continue
    fi
    if [[ $var =~ $con ]]; then
        echo $var " will not be compressed"
    else
        echo $var
        cwebp -q 70 $var -o ${var%.*}.webp
        rm $var
    fi
done
echo "Convert task complete!"
原文链接:https://www.f2er.com/bash/390494.html

猜你在找的Bash相关文章