ImageMagic convert 使用备忘

 

1. 图片剪切

-crop参数:

是从一个图片截取指定区域的子图片.

语法:

convert -crop widthxheight{+-}x{+-}y{%}

width 子图片宽度
height 子图片高度
x 为正数时为从区域左上角的x坐标,为负数时,左上角坐标为0,然后从截出的子图片右边减去x象素宽度.
y 为正数时为从区域左上角的y坐标,为负数时,左上角坐标为0,然后从截出的子图片上边减去y象素高度.

如:

convert -crop 300x400+10+10 src.jpg dest.jpg 从src.jpg坐标为x:10 y:10截取300x400的图片存为dest.jpg
convert -crop 300x400-10+10 src.jpg dest.jpg 从src.jpg坐标为x:0 y:10截取290x400的图片存为dest.jpg

2. 颜色替换

//Change the opaque color (0,0,0) to 255.255.255

convert $1 -fuzz 10% -fill 'rgb(255,255,255)' -opaque 'rgb(0,0,0)' $2

 

3. 在图片上绘画

convert input.tif -fill '#ffffffff' -draw "rectangle 0,1700 9000,2200" output.tif

4. 替换指定颜色为alpha=0

convert input.tif -fuzz 0% -transparent white output.tif

5.扩展canvas

convert -extent 4000x4000 h0_v0_color.jpg tmp.jpg

6. 滚转画面

convert -roll -0+500 tmp.jpg tmp2.jpg

7.获取平均亮度

identify -format "%[mean]\n" filename

This should be the overall mean of all the channels of the image in range 0 to Quantumrange for your IM compile.

If you want the values in the range 0 to 1, then use
identify -format "%[fx:mean]\n" filename
Both should be part of what you see in identify -verbose filename
If you want the mean of any given channel, then use
identify -format "%[fx:mean.r ]\n" filename
for the red channel
You can also multiply it by quantumrange to get the same as %[mean]
identify -format "%[fx:quantumrange*mean]\n" filename

 8. %方法

http://www.imagemagick.org/script/escape.php

https://www.imagemagick.org/Usage/

 

posted @ 2016-09-09 17:20  Reboost  阅读(481)  评论(0)    收藏  举报