发现阿里云的文件上传目录有点大,500G 已经超过50%,考虑须要将早期的图片批量压缩处理一下才行工具
必备工具:优化
yum install ImageMagick阿里云
yum install jpegoptimcode
操做思路,遍历指定的某个文件夹下的全部 jpg 文件,而后识别图片的宽和高,超过1024的直接 resize,不然直接进行图片压缩优化。图片
#!/bin/sh #set -xv if [ $# != 1 ] ; then echo "USAGE: $0 img_full_path" exit 1; fi cd $1 echo 'process root :'$1 ind=1 resizeFile=1 for f in `find . -name "*.jpg"`; do #echo $f; w=`mediainfo $f | grep Width | cut -d":" -f2` h=`mediainfo $f | grep Height | cut -d":" -f2` w=${w//' '/''} w=${w//'pixels'/''} h=${h//' '/''} h=${h//'pixels'/''} tw=$w #echo $f $w; if [ $w -gt 1024 ]; then tw=1024; fi if [ $h -gt 1024 ]; then tw=$(( $w*1024/$h)) fi if [ $tw -lt $w ]; then tf=${f%.*}_m.${f##*.}; echo $f" > "$tf" "$w"x"$h; convert -resize $tw $f $tf mv $tf $f -f let resizeFile=$resizeFile+1 fi jpegoptim $f let ind=$ind+1 done; echo $resizeFile" "$ind;