#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#!/bin/bash
# 查找目录及子目录的图片文件(jpg,gif,png),将大于某值的图片进行压缩处理
# Config
folderPath='/www/wwwroot/salon/attachment/behram_pic' # 图片目录路径
maxSize='100KB' # 图片尺寸允许值
maxWidth=640 # 图片最大宽度
maxHeight=500 # 图片最大高度
quality=80 # 图片质量
# 压缩处理
# Param $folderPath 图片目录
function compress(){
folderPath=$1
if [ -d "$folderPath" ]; then
for file in $(find "$folderPath" \( -name "*.jpg" -or -name "*.gif" -or -name "*.png" \) -type f -size +"$maxSize" ); do
echo $file
# 调用imagemagick resize图片
$(convert -resize "$maxWidth"x"$maxHeight" "$file" -quality "$quality" -colorspace sRGB "$file")
done
else
echo "$folderPath not exists"
fi
}
# 执行compress
compress "$folderPath"
exit 0
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
版权属于:
admin
作品采用:
《
署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
》许可协议授权
评论 (0)