ImageMagick生成缩略图

发布时间:2014-04-22 18:04:24 阅读:1436次

http://www.jincon.com/archives/249/

find ./ -regex '.*\(jpg\|JPG\|png\|jpeg\)' -size +500k

http://justcoding.iteye.com/blog/2022467/

6.当原始文件大于指定的宽高时,才进行图片放大缩小,可使用>命令后缀。

如:convert -resize “100×50>” src.jpg dst.jpg

此命令执行后,dst.jpg图片大小为(67×50),图片保持原有比例。

如:convert -resize “100×50>!” src.jpg dst.jpg

此命令执行后,dst.jpg图片大小为(100×50),图片不保持原有比例。

7.当原始文件小于指定的宽高时,才进行图片放大转换,可使用<命令后缀。

如:convert -resize “100×500<” src.jpg dst.jpg 或者convert -resize “100×100<!” src.jpg dst.jpg

此命令执行后,dst.jpg和src.jpg大小相同,因为原始图片宽比100大。

如:convert -resize “600×600<” src.jpg dst.jpg

此命令执行后,dst.jpg图片大小为(600×450),图片保持原有比例。

如:convert -resize “600×600<!” src.jpg dst.jpg

此命令执行后,dst.jpg图片大小为(600×600),图片不保持原有比例。

8.使用^命令后缀可以使用宽高中较小的那个值作为尺寸

如:convert -resize “300×300^” src.jpg dst.jpg

此命令执行后,dst.jpg图片大小为(400×300),图片保持原有比例,(300:300 < 200:150,选择高作为最小尺寸)。

如:convert -resize “300×200^” src.jpg dst.jpg

此命令执行后,dst.jpg图片大小为(300×225),图片保持原有比例,(300:200 > 200:150,选择宽作为最小尺寸)。

http://www.cnblogs.com/ITtangtang/p/3951240.html

convert +profile '*' [src]{file}.{ext} -quality 80 -resize '280x140^>' -gravity Center -crop 280x140+0+0 +repage [out]{file}_280x140.{ext}

把一张图片按80的质量去压缩(jpg的压缩参数),同时按图片比例非强制缩放成不超过280x140的图片.居中裁剪280x140,去掉图片裁减后的空白和图片exif信息,通常这种指令是为了保证图片大小正好为280x140

http://www.jincon.com/archives/249/

http://elf8848.iteye.com/blog/382528

http://www.cnblogs.com/chenwenbiao/archive/2011/07/25/2116152.html

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

<?php

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

?>

getimgsize.sh

#!/bin/bash
path=$1
echo "path=>"$path
img=$2
echo "img=>"$img
imgsize=`find $path  -name $img |xargs identify|awk '{print $7}'`
if [[ $imgsize == *KB* ]]
then
        var=${imgsize/KB/}
fi
if [[ $imgsize == *MB* ]]
then
        imgsize=${imgsize/MB/}
        var=`echo "$imgsize*1000"|bc`
        var=${var%.*}
fi
echo $var
if [ $var -gt 800 ]
then
        echo "bigpic"
        convert -quality 100 -resize 800x600 $path/$img $path/$img
fi
echo "==============================================================================="

<?php

 system("/bin/bash /app/www/getimgsize.sh $save_dir $filename|tee -a /tmp/resizeimg.log");

?>

php生成缩略图http://www.jb51.net/article/51248.htm

php对于成千上万的图片来生成缩略图,很2

apt-get install imagemagick

通过imagick的convert命令来实现 

bash-3.2# vim imgconvert.sh

  1 #!/bin/bash

  2 img_list=`find /var/www/html/uploadfile -name "php*.jpg" -mtime -1`;

  3 for img in $img_list

  4 do

  5         path=${img%/*}

  6         #echo "path=>"$path

  7         filename=${img##*/}

  8         #echo "filename=>"$filename

  9         fullname=$path/$filename

 10         #echo $fullname

 11         convertfullname=$path/80x66_$filename

 12         echo $convertfullname

 13         echo "------------------------------------------------------------------------"

 14         if [ -e $convertfullname ]; then

 15                 echo "Picture is already converted small"

 16         else

 17                 echo "File does not exists"

 18                 convert -resize 80x66 $fullname $convertfullname

 19         fi

 20 done


[test@web_test ~]$ cat resize.sh
wget "http://www.test.com/20170307/58be14a3e03181382037231.jpg" -O 1.jpg
convert -resize 210x140 1.jpg 1_1.jpg
convert -resize 210 1.jpg 1_1.jpg
convert 1_1.jpg -gravity center -crop 210x140+0+0 1_1.jpg


 2008  identify 58ae37b05bb7c.png

 2021  convert -resize 420x280 X210X140_58ae6b79a1e421260307474.png 1.png
 2025  identify 1.png
 2026  wget http://images11.app.happyjuzi.com/news/201702/23/58ae8ab622103.png -O 11.png
 2030  vim 1.sh
 2031  chmod +x 1.sh
 2032  ./1.sh
 2034  identify 11.png
 2035  convert -resize 210x140 11.png 11_1.png
 2036  wget http://images11.app.happyjuzi.com/news/201702/23/58ae8ab622103.png -O one.png
 2038  convert -resize 210x140 one.png one_1.png
 2040  convert -resize 200 one.png one_2.png
 2041  convert -resize 210 one.png one_2.png
 2042  convert src.jpg -crop 100x100 dest.jpg
 2043  convert one_2.png -crop 210x140 one_3.png
 2045  convert one.png -crop 210x140+50+30 one_4.png
 2047  convert one_2.png -crop 210x140+50+30 one_4.png
 2048  convert one_2.png -crop 210x140+30+30 one_4.png
 2049  convert one_2.png -crop 210x140+20+30 one_4.png
 2050  convert one_2.png -crop 210x140+20+20 one_4.png
 2051  convert one_2.png -crop 210x140+20+0 one_4.png
 2052  convert one_2.png -crop 210x140+0+0 one_4.png
 2053  convert one_2.png -crop 210x140+1+1 one_4.png
 2054  convert one_2.png -gravity center -crop 210x140+0+0 one_4.png
 2055  convert one_2.png -quality 100 -gravity center -crop 210x140+0+0 one_4.png
 2056  history

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:ImageMagick生成缩略图 出自老鄢博客 | 欢迎分享