10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

僕はこうやってテスト用画像を用意する。その1 連番の書いてある画像。(Windows & ImageMagick)

Last updated at Posted at 2015-01-27

追記:以下の内容はImagemagick6の頃の内容です。Imagemagick7以降は最後に追記しておきます。すみません。

テストを行うときはこういう事がよくある。
テスト用画像を400枚用意したい。サイズは800x600。色や画像は何でも良いが、互いに識別できるものでないと、テストの時に困る。

そんな時、私ならこうする。

まず800x600の単色の画像を用意する。
私はPaint.netを使っているが、GIMPでも構わない。
テスト用画像を保存する場所においておこう。今回は「800x600_yellow.png」という名前としよう。800x600_yellow.png

次。ImageMagickをWindowsにインストールする。
こちらからダウンロードしてインストーラを起動すればおしまい。
http://www.imagemagick.org/script/binary-releases.php#windows

次。コマンドプロンプトを起動し、先ほどの画像を配置したディレクトリへ移動する。
そしてこのようなコマンドを入力する。

convert -pointsize 240 -gravity center -annotate 0 "001" -fill black 800x600_yellow.png 800x600_yellow_001.png

すると、こんな画像が生成される。
800x600_yellow_001.png

これで、画像の生成は完了。
あとはコマンドをExcelでもなんでも使って量産すれば良い。
400枚くらい簡単に作れる。

追記:
Excelで、1という表記を001に変換したい場合は、=TEXT(A1,"000") ってな感じでTEXT関数を使うと良い。意外と知らない人がいて驚き。

追記(2017年07月08日):
Imagemagick7だとconvertコマンドは廃止されて、magickというコマンドになったらしいです。こっちの方がWindowsのconvertコマンドと被らないから自分は好きです。こんな感じで文字入りの画像を作れます。背景画像を指定する方法が解らなかったので、塗りつぶしました。参考になれば幸いです。

magick -background yellow -fill black -pointsize 70 label:"001" 001.png

追記(2024年02月25日)
このコマンドで文字を入れられるようでした。OpenAIに聞いたら即座に教えてくれました。便利な世の中になりましたねえ…。

magick convert 800x600_yellow.png -pointsize 240 -gravity center  -fill black -annotate 0 "001" 001.png

001.png

10
9
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
10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?