Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 3 years have passed since last update.

ImageMagick のテキスト描画

0
Last updated at Posted at 2017-12-27

ImageMagick テキスト描画機能についてです。公式マニュアルはこちら。

フォント関連は別エントリに分けたので、ここでは取り上げません。

サンプル画像

% magick convert granite: granite.png
granite.png
granite.png

白文字も黒文字も読みやすく、都合の良いサンプルです。

-annotate

一番有名なオプションは -annotate でしょうか。使い方は以下の通り。

-annotate degrees text
-annotate XdegreesxYdegrees text
-annotate XdegreesxYdegrees{+-}tx{+-}ty text
-annotate {+-}tx{+-}ty text

つまり、-annotate 90x90+100+100 のようにすると。{x:100, y:100} を基準に 90 度回転した文字を描画します。ちなみに、90x90 は x と y で別々に回転を反映させる記法です。残念ながら 90 だけだと動きません。(正直、90+100+100 で動いて欲しい)

% magick convert granite: -annotate 90x90+100+100 Foo Foo90x90+100+100.jpg
Foo90x90+100+100.jpg
Foo90x90+100+100.jpg

さて、まずは初心者が元に引っかかりそうな分かり易い失敗例です。

% magick convert granite: -annotate 0 Foo Foo0.jpg

テキストは左下が基準で、描画領域の上に文字が書かれる為です。

Foo0.jpg 枠外イメージ
Foo0.jpg Foo0+extent20.png

通常は gravity とセットで使うので問題にならないでしょう。

% magick convert granite: -gravity northwest -annotate 0 Foo Foo0-northwest.jpg
% magick convert granite: -gravity center -annotate 0 Foo Foo0-center.jpg
% magick convert granite: -gravity center -annotate 45 Foo Foo45-center.jpg
Foo0-northwest.jpg Foo0-center.jpg Foo45-center.jpg
Foo0-northwest.jpg Foo0-center.jpg Foo45-center.jpg

-gravity の詳細は以下のエントリをご参照下さい。

ImageMagick Gravity 指定
image.png
https://qiita.com/yoya/items/b6926f01b7cb90217e07

テキスト属性

サイズ

-pointsize と -density で指定します。 まずは -pointsize の例を。


density はデフォルト 72 で、これとの組み合わせで文字の大きさが決まります。


色の指定

fill, stroke, undercolor

装飾

shadow 等があります。

レイアウト制御

  • kerning

-draw text

label:

text:

pango:

pango の HTML風なマークダウン記法が使えます。

% magick -background lightblue \
       pango:'  Some  <span size="49152" rise="-20480"
                foreground="red" background="blue"
                 > Big Red on Blue </span>  Text  ' \
       pango_span.gif
pango_span.gif
pango_span.gif

また、pango だと絵文字も使える事があるようです。
Ubuntu での成功報告があります。自分が macOS で試したら駄目でした。

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?