ImageMagick - 笔记整理 (草稿)
Table of Contents
1 ImageMagick
2 信息 : identify
identify Tachikoma.gif # identify -verbose Tachikoma.gif
3 格式转换
convert Tachikoma.gif Tachikoma.png display Tachikoma.png identify Tachikoma.png
4 缩放 修改尺寸
-resize WxH
convert Tachikoma.png -resize 200x100! Tachikoma.resize.png display Tachikoma.resize.png identify Tachikoma.resize.png
5 剪切
-crop | -trim | -shave (WxH+x+y)
convert Tachikoma.png -crop 200x200+300+300 png:- \
| display
6 拼接
纵向 : -append
convert Tachikoma.png -crop 200x200+300+300 \ tachikoma.png \ -append png:- \ | display
横向 +append
convert tachikoma.png -crop 300x300+300+0 \ \( tachikoma.png -crop 300x300+0+0 \) \ +append png:- \ | display
7 合成
-composite
convert Tachikoma.png \ \( smileman.png -geometry 100x100+10+10 \) \ -composite png:- \ | display
8 旋转 翻转
-rotate Degree 和 -flip(上下) -flop(左右)
convert Tachikoma.resize.png \ -rotate 45 \ -flip \ png:- \ | display
9 添加: 边框 文字
边框 : -frame WxH | -bordercolor gray -border WxH
convert Tachikoma.png \ -bordercolor gray -border 50x5 \ png:- \ | display
文字
Draw Text on Existing Canvas : -draw "…"
convert Tachikoma.png \ -font "/System/Library/Fonts/PingFang.ttc" \ -fill pink -pointsize 30 \ -draw "text 10,50 '绘制的文字'" \ -fill yellow -pointsize 60 \ png:- \ | display
Graphy
convert -size 320x120 xc:lightblue \ -draw "fill tomato circle 250,30 310,30 \ fill limegreen circle 55,75 15,80 \ font Candice font-size 72 decorate UnderLine \ fill dodgerblue stroke navy stroke-width 2 \ translate 10,110 rotate -15 text 0,0 ' Anthony '" \ png:- \ | display
Annotate : -annotate {SlewX}x{SlewY}+{X}+{Y} "…"
convert -size 320x100 xc:lightblue -undercolor dodgerblue \ -font Candice -pointsize 72 \ -tile gradient:blue-red \ -annotate 350x350+20+90 'Anthony' \ png:- \ | display
Label : label:
convert -background lightblue -fill blue -font Candice \ -size 300x200 -pointsize 30 \ -gravity center \ -strokewidth 10 -stroke white \ label:'Label\nHello Label' \ png:- \ | display
Caption : Word Wrapped
convert -background lightblue -undercolor blue \ -fill white -font Candice \ -size 300x -pointsize 30 \ -gravity center \ caption:'This is a very long caption line.' \ png:- \ | display
- Text Attributes
- -pointsize
- 1 point is 1/72 inches
- 不指定 则 Auto fit size
- -density 90 (ppi)
- -size Wx 则 Auto fit height 反之亦然
- -fill | -tile
- 从文件 : label:@/path
- 从标准输入 : label:@-
- Ex. echo "Anthony" | convert label:@-
-strokewidth 2 -stroke blue
convert -background black -fill white -font Candice \ -size x200 \ -strokewidth 8 -stroke white \ label:'A' \ png:- \ | display
- Inter-character Kerning : -kerning 1
- Inter-Word Spacing : -interword-spacing 1
- Inter-Line Spacing : -interline-spacing 5
- -pointsize
Pango : Basic Formatted Text
convert -background lightblue -size 150 \ -define "pango:justify=true" \ pango:"Contributions to IM Examples are welcome." \ png:- \ | display
- Auto word wrap (or char wrap for chinese)
- -define pango:justify=true
generate barcodes (font: http://www.idautomation.com/fonts/free/)
convert -pointsize 16 \ -font IDAutomationHC39M \ -bordercolor white -border 5x5 \ label:'*314-76*' \ png:- \ | display
Yin Yang
convert -pointsize 72 -density 288 \ -font Symbola \ label:'☯' \ -rotate 270 \ png:- \ | display
10 效果
特效
- 加噪声 -noise 3
- 油画 : -paint 4
- 内爆 : -implode 1
- 胶片曝光 : -solarize 42
- 铅笔 : -charcoal 2
- 散射 (毛玻璃) : -spread 30
- 高斯模糊 : -blur 80 (80x5: 5 : Sigma )
- 漩涡 : -swirl 67
- [凸起|凹陷] : [-|+]raise 5x5 ()
- 锐化 : -sharpen 2
示例
convert Tachikoma.png \ -swirl 80 \ -frame 30x30 +raise 10x10 \ png:- \ | display
颜色
- 反色 : -negate
- 黑白 : -monochrome
- 着色 : -colorize [255 | 100/0/125]
- 填色 : -opaque khaki
- 透明 : -transparent
- 移除 : -flatten
- -modulate brightness,saturation,hue
示例
convert Tachikoma.png \ -transparent white \ png:- \ | display