imgresize.sh

php中

<?php

system("/bin/bash /app/www/cron/lib/imgresize.sh $imgname 210x140");

?>

[root@web_pre lib]# cat imgresize.sh

img=$1
echo "img=>"$img
size=$2
ext=${img##*.}
echo $ext
filename=${img##*/}
path=${img%/*}
if [ "$size" == "210x140" ];then
newimg=$path/X210X140_$filename
echo $newimg
convert -quality 100 -resize 210 $img $newimg
convert -quality 100 $newimg -gravity center -crop 210x140+0+0 $newimg
if [ "$ext" == "gif" ];then
  convert $newimg -trim +repage $newimg
fi
size=`identify -format "%wx%h" $newimg`
if [ "$size" == "210x140" ];then
echo "ok"
else
echo "no"
convert -quality 100 -resize x210 $img $newimg
convert -quality 100 $newimg -gravity center -crop 210x140+0+0 $newimg
if [ "$ext" == "gif" ];then
  convert $newimg -trim +repage $newimg
fi
fi
else
newimg=$path/X90X60_$filename
convert -quality 100 -resize 90 $img $newimg
convert -quality 100 $newimg -gravity center -crop 90x60+0+0 $newimg
if [ "$ext" == "gif" ];then
  convert $newimg -trim +repage $newimg
fi
size=`identify -format "%wx%h" $newimg`
if [ "$size" == "90x60" ];then
echo "ok"
else
echo "no"
convert -quality 100 -resize x90 $img $newimg
convert -quality 100 $newimg -gravity center -crop 90x60+0+0 $newimg
if [ "$ext" == "gif" ];then
  convert $newimg -trim +repage $newimg
fi
fi
fi

    A+
发布日期:2017年05月13日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: