LoginSignup
22
15

More than 5 years have passed since last update.

ImageMagickで文字画像作成

Last updated at Posted at 2014-04-18

ImageMagickで文字画像作成

大量のダミー画像が必要になった時とかにシェルスクリプトで回すと便利かもしれない。

要点

  • フォント指定する
  • captionで書くと適当に幅に合わせて改行してくれる
bash
convert \
  -size 640x854  \
  -background "#C0C0C0"  \
  -fill "#FFFF00"  \
  -font aquafont.ttf \
  caption:"サンプル\n改行も\nできます" \
  output.png

ちなみに、出力に標準出力を指定する事もできる。
その場合は、ファイル名の前にフォーマット指定が必要。

bash
convert \
  -font aquafont.ttf \
  caption:"てすと" \
  png:-

Data URI scheme で出力してみたり

bash
echo "data:image/png;base64,"$(convert -font aquafont.ttf caption:"てすと"  png:- | base64)
22
15
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
22
15