Friday, March 02, 2007

ImageMagickで旗がなびくようなGIFアニメーションを作成する

ImageMagickで旗がなびくようなGIFアニメーションを作成するには、
以下のバッチファイルを実行します。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.1-Q16

%im%\convert.exe sample7.jpg -fx (1+cos(pi*i/20)*0.2)*p -mattecolor black -frame 10x10 -fx p{i,j+cos(pi*i/20)*5} f1.gif
%im%\convert.exe sample7.jpg -fx (1+cos(pi*(i/20+0.4))*0.2)*p -mattecolor black -frame 10x10 -fx p{i,j+cos(pi*(i/20+0.4))*5} f2.gif
%im%\convert.exe sample7.jpg -fx (1+cos(pi*(i/20+0.8))*0.2)*p -mattecolor black -frame 10x10 -fx p{i,j+cos(pi*(i/20+0.8))*5} f3.gif
%im%\convert.exe sample7.jpg -fx (1+cos(pi*(i/20+1.2))*0.2)*p -mattecolor black -frame 10x10 -fx p{i,j+cos(pi*(i/20+1.2))*5} f4.gif
%im%\convert.exe sample7.jpg -fx (1+cos(pi*(i/20+1.6))*0.2)*p -mattecolor black -frame 10x10 -fx p{i,j+cos(pi*(i/20+1.6))*5} f5.gif
%im%\convert.exe sample7.jpg -fx (1+cos(pi*(i/20+2.0))*0.2)*p -mattecolor black -frame 10x10 -fx p{i,j+cos(pi*(i/20+2.0))*5} f6.gif
%im%\convert.exe sample7.jpg -fx (1+cos(pi*(i/20+2.4))*0.2)*p -mattecolor black -frame 10x10 -fx p{i,j+cos((pi*i/20+2.4))*5} f7.gif
%im%\convert.exe sample7.jpg -fx (1+cos(pi*(i/20+2.8))*0.2)*p -mattecolor black -frame 10x10 -fx p{i,j+cos(pi*(i/20+2.8))*5} f8.gif
%im%\convert.exe sample7.jpg -fx (1+cos(pi*(i/20+3.2))*0.2)*p -mattecolor black -frame 10x10 -fx p{i,j+cos(pi*(i/20+3.2))*5} f9.gif
%im%\convert.exe sample7.jpg -fx (1+cos(pi*(i/20+3.6))*0.2)*p -mattecolor black -frame 10x10 -fx p{i,j+cos(pi*(i/20+3.6))*5} f10.gif
%im%\convert.exe f1.gif f2.gif f3.gif f4.gif f5.gif f6.gif f7.gif f8.gif f9.gif f10.gif -set delay 15 -loop 0 sample91.gif

元画像(sample7.jpg)


出力画像(sample91.gif)

Thursday, March 01, 2007

ImageMagickで2色の波模様を描画する

ImageMagickで2色の波模様を描画するには、
以下のバッチファイルを実行します。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.1-Q16
%im%\convert.exe -size 100x100 xc:white ( xc:#ffffcc xc:#bbddff +append -resize 2x1 ) -fx v.p{1+cos(pi*i/15),0} sample90a.jpg
%im%\convert.exe -size 100x100 xc:white ( xc:#bb400c xc:#fee6e6 +append -resize 2x1 ) -fx v.p{1+cos(pi*i/15),0} sample90b.jpg

出力画像(sample90a.jpg)


出力画像(sample90b.jpg)

Wednesday, February 28, 2007

ImageMagickで吹き出しを作成する - その4

ImageMagickで影の部分だけ半透明の吹き出しPNG画像を
生成するには、以下のバッチファイルを実行します。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.1-Q16
%im%\convert.exe -size 200x150 xc:none -fill #fce769 -stroke #f6b739 -strokewidth 4 -draw "roundrectangle 5,5 194,99 20,20" -stroke #fce769 -draw "polygon 70,99 50,149 80,99" -stroke #f6b739 -draw "polyline 60,99 70,99 50,149 80,99 89,99" ( +clone -affine 1,0,0,0.5,0,75 -transform -shear 30x0 -channel RGBA -fx "p!=0?#D0D0D080:0" -blur 0x1 ) +swap -mosaic sample124a.png

出力画像(sample124a.jpg)






以下のコマンドで吹き出し画像を重ね合わせることができます。
%im%\convert.exe sample9.jpg sample124a.png -geometry +30+20 -composite sample124b.jpg

元画像(sample9.jpg)


出力画像(sample124b.jpg)


関連項目
ImageMagickで、半透明グラデーションの吹き出しを描画する
ImageMagickで、明度を変えた吹き出しを描画する


ImageMagickで画像に波模様をつける

ImageMagickで画像に波模様をつけるには、
以下のバッチファイルを実行します。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.1-Q16
%im%\convert.exe sample7.jpg -fx (1+cos(pi*i/10)*0.2)*p sample89a.jpg
%im%\convert.exe sample7.jpg -fx (1+cos(pi*j/10)*0.2)*p sample89b.jpg

元画像(sample7.jpg)


出力画像(sample89a.jpg)


出力画像(sample89b.jpg)

ImageMagickで半透明のぼかし四角形と文字列を重ね合わせる

ImageMagickで半透明のぼかし四角形と文字列を重ね合わせるには、
以下のバッチファイルを実行します。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.1-Q16

%im%\convert.exe sample7.jpg ( -size 150x100 xc:none -fill #bbddff80 -channel RGBA -draw "rectangle 50,25 100,75" -blur 0x3 ) -composite -gravity center -fill white -annotate 0 "Sample" sample88.jpg

元画像(sample7.jpg)


出力画像(sample88.jpg)

Monday, February 26, 2007

ImageMagickで重ね合わせの位置を指定する

-gravityオプションを用いて、重ね合わせの位置を
指定することもできます(座標指定の場合は-geometryを使用します)。

元画像(sample7.jpg)


元画像2(yourlogo2.png)

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.1-Q16
rem 左上に配置
%im%\convert.exe sample7.jpg yourlogo.png -gravity northwest -composite sample87a.jpg

左上に重ね合わせた画像(sample87a.jpg)


rem 中央上に配置
%im%\convert.exe sample7.jpg yourlogo.png -gravity north -composite sample87b.jpg
中央上に重ね合わせた画像(sample87b.jpg)


rem 右上に配置
%im%\convert.exe sample7.jpg yourlogo.png -gravity northeast -composite sample87c.jpg

右上に重ね合わせた画像(sample87c.jpg)


rem 中央左に配置
%im%\convert.exe sample7.jpg yourlogo.png -gravity west -composite sample87d.jpg

中央左に重ね合わせた画像(sample87d.jpg)


rem 中央に配置
%im%\convert.exe sample7.jpg yourlogo.png -gravity center -composite sample87e.jpg

中央に重ね合わせた画像(sample87e.jpg)


rem 中央右に配置
%im%\convert.exe sample7.jpg yourlogo.png -gravity east -composite sample87f.jpg

中央右に重ね合わせた画像(sample87f.jpg)


rem 左下に配置
%im%\convert.exe sample7.jpg yourlogo.png -gravity southwest -composite sample87g.jpg

左下に重ね合わせた画像(sample87g.jpg)


rem 中央下に配置
%im%\convert.exe sample7.jpg yourlogo.png -gravity south -composite sample87h.jpg

中央下に重ね合わせた画像(sample87h.jpg)


rem 右下に配置
%im%\convert.exe sample7.jpg yourlogo.png -gravity southeast -composite sample87i.jpg

右下に重ね合わせた画像(sample87i.jpg)


関連項目
ImageMagickで重ね合わせの位置を指定する - その2
ImageMagickで2つの画像を重ね合わせる

Sunday, February 25, 2007

ImageMagickで画像の上下左右を切り落とす

ImageMagickで画像の上下左右を切り落とすには、
-chopオプションを使用します。-gravityオプションを
併用することにより、切り落とす方向を指定できます。
元画像(sample4.jpg)


rem 環境によって変えてねset im=C:\Progra~1\ImageMagick-6.3.1-Q16
rem 左を10ピクセル切り落とし
%im%\convert.exe sample4.jpg -chop 10x0 sample86a.jpg
出力画像(sample86a.jpg)


rem 左を10ピクセル、上を20ピクセル切り落とし
%im%\convert.exe sample4.jpg -chop 10x20 sample86b.jpg
出力画像(sample86b.jpg)


rem 右を40ピクセル切り落とし
%im%\convert.exe sample4.jpg -gravity east -chop 40x0 sample86c.jpg
出力画像(sample86c.jpg)


rem 下を30ピクセル切り落とし
%im%\convert.exe sample4.jpg -gravity south -chop 0x30 sample86d.jpg
出力画像(samplle86d.jpg)

Friday, February 23, 2007

ImageMagickで二重縁取りの文字列を描画する

ImageMagickで二重縁取りの文字列を描画するには、
ストロークの太さ(-strokewidthで指定)が異なる
文字列を同じ場所に重ね書きします。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.0-Q16
%im%\convert.exe -size 200x60 xc:#ffffff -fill #f6b739 -stroke #f6b739 -strokewidth 6 -pointsize 50 -draw "text 0,45 Sample" -fill #fad759 -stroke #ffffff -strokewidth 2 -draw "text 0,45 Sample" sample29.jpg

出力画像(sample29.jpg)

Thursday, February 22, 2007

ImageMagickで金属プレート風の画像を描画する

ImageMagickで金属プレート風の画像を描画するには、
以下のバッチファイルを実行します。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.1-Q16
%im%\convert.exe -size 150x100 gradient:#f5f5f5-#a3a3a3 ( -size 150x100 xc:none -matte -channel RGBA -fx sin(pi*i/w)*0.1+0.9 -channel A -fx 0.5 ) -composite -stroke none -draw "fill #909090 font-size 26 text 29,59 'Sample' fill #ffffff font-size 26 text 31,61 'Sample' fill #d0d0d0 font-size 26 text 30,60 'Sample'" -raise 2x2 sample84.gif

以下の項目を実行しています。
・グラデーション塗り
・-fxで画像左右をわずかに影付け
・文字列を2回描画して彫りこんだ感じに
・-raiseで厚みを持たせる

出力画像(sample84.gif)


関連項目
ImageMagickで金属プレート風の画像を描画する - その2


Wednesday, February 21, 2007

ImageMagickで画像を縁取りする

ImageMagickで画像の縁取りするには
以下のバッチファイルを実行します。
(画像をぼかした後、指定色で塗り替えて縁取りするという方法)

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.1-Q16
%im%\convert.exe -size 100x100 xc:none ( sample2.png -matte -channel RGBA -blur 0x1 -fx p==0?0:#ccddff ) sample2.png -background none -flatten sample83a.gif

元画像(sample2.png)


出力画像(sample83a.gif)


-blurの値を変更することで、縁取り線の幅を調節できます。
%im%\convert.exe -size 100x100 xc:none ( sample2.png -matte -channel RGBA -blur 0x0.2 -fx p==0?0:#ccddff ) sample2.png -background none -flatten sample83b.gif

Tuesday, February 20, 2007

ImageMagickで四角の隅をグラデーションのように塗る

ImageMagickで四角の隅をグラデーションのように塗るには、
以下のように2色で図形描画後、ぼかします。

rem 環境によって変えてねset im=C:\Progra~1\ImageMagick-6.3.1-Q16
%im%\convert.exe -size 100x100 xc:#ccddff -fill white -draw "rectangle 10,10 90,90" -blur 0x10 sample82a.png

出力画像(sample82a.jpg)


関連項目
ImageMagickで四角の墨をグラデーションのように塗る - その2

Monday, February 19, 2007

ImageMagickで画像の四隅を切り取る

ImageMagickで画像の四隅を切り取るには、以下の
バッチファイルを実行します。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.1-Q16
rem 隅のマスク画像を作成
%im%\convert.exe -size 10x10 xc:black -fx "(i+j)>9?1:0" mask1.png
rem マスク画像を作成(隅のマスク画像を左上・右上・左下・右下に配置)
%im%\convert.exe -size 200x150 xc:white -gravity northwest mask1.png -composite -gravity northeast ( mask1.png -flop ) -composite -gravity southwest ( mask1.png -flip ) -composite -gravity southeast ( mask1.png -flip -flop ) -composite -matte -channel A -fx p.r==1?1:0 mask.png
rem マスク画像を使用して元画像を切り抜き
%im%\convert.exe sample1.jpg -matte mask.png -compose dst_in -composite sample81.gif

元画像(sample1.jpg)


出力画像(sample81.jpg)

Sunday, February 18, 2007

ImageMagickで2値化したのちグラデーションで塗りつぶす

ImageMagickで2値化したのちグラデーションで塗りつぶすには、
以下のバッチファイルのように、-thresholdで閾値を設定して
2値化した後、グラデーション塗りつぶします。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.1-Q16
%im%\convert.exe -size 100x100 gradient:#80ffff-#e0ff80 ( sample5.jpg -threshold 53000 -negate -matte -channel A -fx p==1?1:0 ) -compose screen -composite sample80a.jpg
%im%\convert.exe sample5.jpg -threshold 53000 -matte -channel A -fx p==1?1:0 ( -size 100x100 gradient:#80ffff-#e0ff80 ) -compose screen -composite sample80b.jpg

元画像(sample5.jpg)


出力画像(sample80a.jpg)

Saturday, February 17, 2007

ImageMagickで鏡面映り込みを作成する - その2

ImageMagickでちょっと傾けた鏡面映り込みを
作成するには、以下のバッチファイルを実行します。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.1-Q16

rem 反転&半透明グラデーションをかけて
%im%\convert.exe sample4.jpg -bordercolor #c0c0c0 -border 1x1 -channel A -fx "u!=0?(j/h)*0.6:0" -flip sample4t.png

rem 縦に連結+傾け
%im%\convert.exe sample4.jpg -bordercolor #c0c0c0 -border 1x1 sample4t.png -append -background none -shear 0x5 -gravity center -extent 220x220 sample79a.png

rem jpgで出力
%im%\convert.exe -size 220x220 xc:black sample79a.png -composite sample79b.jpg

背景色を変更したい場合は最後の「jpgで出力」のxc:blackの部分を変えます。

元画像(sample4.jpg)


出力画像(sample79a.jpg)


Friday, February 16, 2007

ImageMagickで角丸四角の影付き枠線を描画する

ImageMagickで角丸四角の影付き枠線を描画するには、
以下のバッチファイルを実行します。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.1-Q16
%im%\convert.exe -size 100x100 xc:none -stroke #ccddff -fill none -draw "stroke-width 2 roundrectangle 5,5 95,95 10,10" ( +clone -background #000000 -shadow 40x3+2+2 ) +swap -background white -mosaic sample78.gif

出力画像(sample78.gif)

Thursday, February 15, 2007

ImageMagickで画像を角丸四角に切り取って端折処理する

ImageMagickで画像を角丸に切り取って端折処理するには、
以下のバッチファイルを実行します。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.1-Q16
rem マスクを作って
%im%\convert.exe -size 40x40 xc:none -matte -channel RGBA -fill #ffffffff -draw "roundrectangle 0,0 60,60 20,20" -fx "(i+j)>40?0:u" mask.png
rem グラデーションを作って
%im%\convert.exe -size 60x60 gradient:#ffffff-#d0d0d0 -rotate -45 -crop 40x40+20+20 grad1.png
rem 重ね合わせ+厚み表現のための線を描画
%im%\convert.exe -size 40x40 grad1.png mask.png -compose dst_in -composite -stroke #ffffffff -fill none -draw "roundrectangle 0,0 60,60 20,20" dogear.png
rem 角丸四角切り取りのためのマスク
%im%\convert.exe -size 200x150 -matte -channel RGBA xc:none -background none -fill white -stroke white -draw "roundrectangle 0,0 199,149 20,20" mask2.png
rem 角丸四角切り取り
%im%\convert.exe -size 200x150 sample1.jpg -matte mask2.png -compose dst_in -composite clipped.png
rem 角丸四角から右下を削って折り曲がった部分を重ねる
%im%\convert.exe -size 200x150 clipped.png -matte -channel RGBA -fx "(i+j)>(180+130)?0:u" dogear.png -geometry +160+110 -compose atop -composite sample77a.gif
rem ついでに影つけ
%im%\convert.exe -size 200x150 xc:white sample77a.gif ( +clone -background #000000 -shadow 40x2+3+3 ) +swap -mosaic sample77b.jpg

元画像(sample1.jpg)


出力画像(sample77b.jpg)

Wednesday, February 14, 2007

ImageMagickで文字列がぼやけていくGIFアニメーションを作成する

文字がぼやけていくGIFアニメーションを作成するには
以下のバッチファイルを実行します。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.1-Q16
%im%\convert.exe -size 100x100 xc:white -fill black -draw "font-size 18 text 20,55 'Sample'" f1.gif
%im%\convert.exe -size 100x100 xc:white -fill black -draw "font-size 18 text 20,55 'Sample'" -blur 0x1 f2.gif
%im%\convert.exe -size 100x100 xc:white -fill black -draw "font-size 18 text 20,55 'Sample'" -blur 0x2 f3.gif
%im%\convert.exe -size 100x100 xc:white -fill black -draw "font-size 18 text 20,55 'Sample'" -blur 0x3 f4.gif
%im%\convert.exe -size 100x100 xc:white -fill black -draw "font-size 18 text 20,55 'Sample'" -blur 0x4 f5.gif
%im%\convert.exe -size 100x100 xc:white -fill black -draw "font-size 18 text 20,55 'Sample'" -blur 0x5 f6.gif
%im%\convert.exe -size 100x100 xc:white -fill black -draw "font-size 18 text 20,55 'Sample'" -blur 0x7 f7.gif
%im%\convert.exe -size 100x100 xc:white -fill black -draw "font-size 18 text 20,55 'Sample'" -blur 0x9 f8.gif
%im%\convert.exe -size 100x100 xc:white -fill black -draw "font-size 18 text 20,55 'Sample'" -blur 0x12 f9.gif
%im%\convert.exe -size 100x100 xc:white -fill black -draw "font-size 18 text 20,55 'Sample'" -blur 0x20 f10.gif

%im%\convert.exe f1.gif f2.gif f3.gif f4.gif f5.gif f6.gif f7.gif f8.gif f9.gif f10.gif -set delay 20 -loop 0 sample76.gif

出力画像(sample76.gif)






















Tuesday, February 13, 2007

ImageMagickで透明な文字列を描画する

以下の方法で透明な文字列を描画することもできます。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.1-Q16
%im%\convert.exe -size 100x100 xc:none -fill white +antialias -draw "font-size 18 text 0,55 'Transparent'" -channel RGBA -negate -fx "p!=1?0:#fad759" sample76a.gif

元画像(sample1.jpg)


出力画像(sample76a.gif)


他の画像と重ね合わせると、字の部分が透けます。
%im%\convert.exe sample1.jpg sample76a.gif -geometry +50+25 -composite sample76b.png

出力画像(sample76b.png)


今度は、半透明の黒背景に透明な文字列の画像を生成します。
%im%\convert.exe -size 100x100 xc:#00000080 -channel RGBA -fill #000000ff +antialias -draw "font-size 18 text 0,55 'Transparent'" -fx "p==#000000?0:p" sample76c.png

出力画像(sample76c.png)


他の画像と重ね合わせると半透明・透明に透けます。
%im%\convert.exe sample1.jpg sample76c.png -geometry +50+25 -composite sample76d.png

出力画像(sample76d.png)