LoginSignup
32
38

More than 5 years have passed since last update.

ImageMagick 画像中に文字を入れる

Last updated at Posted at 2015-10-10

ImageMagickにて、画像中の指定位置に文字列を書き込む方法を記述する。その際、フォント名を指定する。

使用バージョン

  • ImageMagick 6.9.1-4 Q16

コマンド例
convert -size 640x400 -depth 8 gray:circle_640x400.raw -fill #101010 +antialias -font "Meiryo-&-Meiryo-Italic-&-Meiryo-UI-&-Meiryo-UI-Italic" -gravity South -annotate +0+32 "グレーの円" -depth 8 gray:circle_640x400_text.raw

位置指定

-gravityオプションを使用する。
画像上側を北(North)、下側を南(South)、左側を西(West)、右側を東(East)として、この組み合わせで指定する。
中央はCenterと指定する。

本例では-gravity Southを指定しており、下側中央配置である。

文字列を書き込む

-annotateオプションを使用する。

座標指定

{+|-}tx{+|-}tyにて指定する。原点(画像の左上)からの相対位置を示す。
Xの正方向は右側、Yの正方向は上側である。
-gravityオプション指定があるときは、その指定からの相対位置となる。

文字列

位置指定の後に配置する。ダブルクォーテーションで囲むことで、半角スペースを含んだ文字列を指定できる。

フォント指定

-annotate前で-fontオプションを使用する。
使用できるフォントの一覧を次のコマンドで確認できる。
convert -list font

> convert -list font

Path: Windows Fonts
  Font: Arial
    family: Arial
    style: Normal
    stretch: Normal
    weight: 400
    glyphs: c:\windows\fonts\arial.ttf
  Font: Arial-Black
    family: Arial
    style: Normal
    stretch: Normal
    weight: 900
    glyphs: c:\windows\fonts\ariblk.ttf
(以下略)

この、Font:の後の文字列を-fontオプションで指定する。

フォントサイズの指定には、-pointsizeオプションを指定する。

-font "Meiryo-&-Meiryo-Italic-&-Meiryo-UI-&-Meiryo-UI-Italic" -pointsize 16

その他

-fill オプション

書き込む文字列の画素値を指定する。

+antialiasオプション

文字のアンチエイリアスをOFFにする。

32
38
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
32
38