WANtaroHP (Mac.ImageMagick)

利用可能フォントの一覧を出力

convert -list font

上記コマンドにより,以下のようなリストがフォント毎に出力されます.

  Font: Tahoma
    family: Tahoma
    style: Normal
    stretch: Normal
    weight: 400
    glyphs: /Library/Fonts/Tahoma.ttf


指定画像ファイルの余白を調整して別名で書き出す

下の事例では,余白を有する元ファイルは不要なのでこれを削除し,余白調整後のファイル名を元ファイル名に書き換えています.

convert fig_acc_fft.png -trim -bordercolor white -border 10x10 fig_acc_fftm.png
rm fig_acc_fft.png
mv fig_acc_fftm.png fig_acc_fft.png


指定 pdf ファイルの余白を調整して png に変換

convert -trim -density 300 flow.pdf -resize 50% -bordercolor "transparent" -border 10x10 fig_flow.png

convert -trim -density 300 a.pdf -quality 100 a.png


ディレクトリ内全 eps の余白を調整して png に変換

ps を 90 度回転させて png にするには,-rotate 90 を加えればよい.

#!/bin/bash
#mogrify -rotate 90 -trim -density 300 -bordercolor 'transparent' -border 10x10 -format png *.ps
mogrify -trim -density 300 -bordercolor 'transparent' -border 10x10 -format png *.eps


ファビコンを作る

#! /bin/bash
convert -trim -background none -fill white -font '/Library/Fonts/Tahoma Bold.ttf' -pointsize 14 label:M test0.png
convert -size 16x16 canvas:brown test1.png
composite -gravity center test0.png test1.png test2.png
convert test2.png -colors 256 favicon.ico


バナーを作る

#!/bin/bash
array='Mac.F90 Mac.Py3 Mac.GMT5 Mac.IMK Mac.Diary Mac.Others Mac.About Blog'
for var in ${array}
do
    convert -trim -background none -fill navy -font '/Library/Fonts/Tahoma bold.ttf' -pointsize 12 label:WANtaroHP wan0U.png
    convert -trim -background none -fill navy -font '/Library/Fonts/Tahoma bold.ttf' -pointsize 12 label:$var wan0D.png
    convert -bordercolor none -border 0x3 wan0U.png temp0U.png
    convert -bordercolor none -border 0x4 wan0D.png temp0D.png
    convert -size 88x31 plasma:white-white wan3b.png
    composite -gravity north temp0U.png wan3b.png temp1.png
    composite -gravity south temp0D.png temp1.png temp.png
    convert -raise 3 temp.png wanz.png

    mv 'wanz.png' 'WAN_'${var/Mac./}'.png'
done
rm temp*.png
rm wan*.png


文字付き短冊を作る

ImageMagick で使用可能なフォントは,「convert -list font」で確認できます.

convert -trim -background none -fill black -font "/System/Library/Fonts/Menlo.ttc" -pointsize 15 label:"AliceBlue" _u.png
convert -trim -background none -fill black -font "/System/Library/Fonts/Menlo.ttc" -pointsize 15 label:"#f0f8ff (240,248,255)" _d.png
convert -size 196x36 xc:#f0f8ff _b.png
composite -gravity north _u.png _b.png _bu.png
composite -gravity south _d.png _bu.png _bud.png
convert _bud.png -bordercolor "#f0f8ff" -border 2x2 _temp.png
cp _temp.png png_strip/img_f0f8ff.png


浮き出した文字画像を作る

convert -size 450x100 xc:transparent -font '/Library/Fonts/Tahoma Bold.ttf' -pointsize 50 \
-fill black -annotate +24+64 'WANtaroHP' \
-fill white -annotate +26+66 'WANtaroHP' \
-fill '#ffd39b' -annotate +25+65 'WANtaroHP' \
_u.png
convert -size 450x100 xc:transparent -font '/Library/Fonts/Tahoma Bold.ttf' -pointsize 40 \
-fill black -annotate +24+64 'Programing on Mac' \
-fill white -annotate +26+66 'Programing on Mac' \
-fill '#ffd39b' -annotate +25+65 'Programing on Mac' \
_d.png
convert -trim _u.png _u1.png
convert -trim _d.png _d1.png
convert -size 450x95 xc:transparent _base.png
composite -gravity north _u1.png _base.png _temp.png
composite -gravity south _d1.png _temp.png _ud.png
convert -rotate -90 _ud.png logo.png


リンゴマークの画像作成 (おそらくMacのみ)

リンゴマークの出力は,[shift] + [option] + [k] でできます.

convert -size 200x200 xc:#000000 -font /System/Library/Fonts/Keyboard.ttf -pointsize 100 -fill white -draw "text 50,150 " test1.png
convert -size 200x200 xc:#c0c0c0 -font /System/Library/Fonts/Keyboard.ttf -pointsize 100 -fill white -draw "text 50,150 " test2.png
convert -size 200x200 xc:#191970 -font /System/Library/Fonts/Keyboard.ttf -pointsize 100 -fill white -draw "text 50 150 " test3.png
convert -size 200x200 xc:#191970 -tile gradient:#ffffff-#ff00ff -font /System/Library/Fonts/Keyboard.ttf -pointsize 100 -draw "text 50,150 " test4.png

convert -size 200x200 xc:transparent -font /System/Library/Fonts/Keyboard.ttf -pointsize 120 \
-fill black -annotate +34+134 '' \
-fill white -annotate +36+136 '' \
-fill '#ffd39b' -annotate +35+135 '' \
test5.png


簡単な数表を作成して画像ファイルと連結する

下の例では,

  • ヒアドキュメントで作成したファイル xxx (label:@xxx) を読み込み,テキストを書き込んだ画像 _front.png を作成します.
  • 1346x844 の白い画像 _back.png を作成し,これに _front.png を真ん中に重ね合わせ,画像 _text.png を作成します.
convert -trim -background white -fill black -font /System/Library/Fonts/Menlo.ttc -pointsize 40 label:@_${fcase}.txt _front.png
convert -size 1346x844 xc:"#ffffff" _back.png
convert _back.png _front.png -gravity center -composite _text.png

下の例では,fig0.png の上部に,-spliceにより高さ62ピクセルの空白を追加し,画像_s1.pngを作成しています. -spliceの後ろに指定する空白の大きさは,幅x高さですが,この事例の場合,幅に0以外を指定すると画像が左右に2分され,真ん中に空白が入ってしまうので注意.

convert fig0.png -background "#ffffff" -gravity north -splice 0x62 _s1.png

+append は画像を横に連結,-append は画像を縦に連結します.

convert +append fig1.png fig2.png _out1.png
convert +append fig3.png fig4.png _out2.png
convert -append _out1.png _out2.png fig_out.png

実際の使用例を下に示します.

fcase=int0_C
cat << EOT > _${fcase}.txt
------------------------------------
 Load           | Internal pressure
------------------------------------
 Water Level    | EL.104.85m
------------------------------------
 Section Level  | EL.81.50m
------------------------------------
 Concrete       | Ec = 26000 MPa
 (Elastic body) | µc = 0.20
------------------------------------
 Bedrock        | Eg = 1000 MPa
 (Elastic body) | µg = 0.25
------------------------------------
EOT
fcase=int1_C
cat << EOT > _${fcase}.txt
------------------------------------
 Load           | Internal pressure
------------------------------------
 Water Level    | EL.121.20m
------------------------------------
 Section Level  | EL.81.50m
------------------------------------
 Concrete       | Ec = 26000 MPa
 (Elastic body) | µc = 0.20
------------------------------------
 Bedrock        | Eg = 1000 MPa
 (Elastic body) | µg = 0.25
------------------------------------
EOT
for fcase in int0_C int1_C
do
    convert -trim -background white -fill black -font /System/Library/Fonts/Menlo.ttc -pointsize 40 label:@_${fcase}.txt _front.png
    convert -size 1346x844 xc:"#ffffff" _back.png
    convert _back.png _front.png -gravity center -composite _text.png
    convert fig_plnt_${fcase}_stress1.png -background "#ffffff" -gravity north -splice 0x62 _s1.png
    convert fig_plnt_${fcase}_stress2.png -background "#ffffff" -gravity north -splice 0x62 _s2.png
    convert fig_plnt_${fcase}_stress3.png -background "#ffffff" -gravity north -splice 0x62 _s3.png
    convert +append fig_plnt_${fcase}_disp.png _text.png _out1.png
    convert +append fig_plnt_${fcase}_vect1.png fig_plnt_${fcase}_vect2.png _out2.png
    convert +append fig_plnt_${fcase}_cont1.png _s1.png _out3.png
    convert +append fig_plnt_${fcase}_cont2.png _s2.png _out4.png
    convert +append fig_plnt_${fcase}_cont3.png _s3.png _out5.png
    convert -append _out1.png _out2.png _out3.png _out4.png _out5.png fig_plnt_${fcase}.png
done
rm _*.png


inserted by FC2 system