yum install ImageMagick
反转
convert -flop reverse.jpg reversed.jpg # 水平反转 convert -flip reverse.jpg reversed.jpg # 垂直反转 convert -flip reverse.gif reversed.gif # 垂直反转 GIF 动图
批量缩小 gif (支持缩小动图)
# 仅处理宽度大于 200 的 .gif find . -type f -name "*.gif" | while read line; echo $line; convert -resize '200>' $line $line; end
批量生成缩略图
filename.png –> filename_thumb.png 新生成,不是覆盖
find . -type f -name "*.png" | while read line; echo $line;convert -resize 450x250 -quality 80 $line (string split -r -m1 . $line)[1]_thumb.jpg; end # 或 find . -type f -name "*.png" | while read line echo $line convert -resize 450x250 -quality 80 $line (string split -r -m1 . $line)[1]_thumb.jpg end
批量压缩图片大小
# 将宽度大于 800 的图片处理成宽为 800 的图片 find ./ -type f -regextype 'posix-egrep' -iregex '.*\.(jpg|png|gif)' | while read line do echo $line convert -resize '800>' $line $line done # 多行转成一行: # bash: find ./ -type f -regextype 'posix-egrep' -iregex '.*\.(jpg|png|gif)' | while read line; do echo $line; convert -resize '800>' $line $line; done # fish: find ./ -type f -regextype 'posix-egrep' -iregex '.*\.(jpg|png|gif)' | while read line; echo $line; convert -resize '800>' $line $line; end
批量转换 png 为 jpg
// fish shell find . -type f -name "*.png" | while read line; echo $line; echo convert -quality 80 $line (string split -r -m1 . $line)[1].jpg; end # convert -resize 1280x800 -quality 80 $line (string split -r -m1 . $line)[1].jpg