發現阿里雲的文件上傳目錄有點大,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;