LoginSignup
16
18

More than 5 years have passed since last update.

ImageMagick でダミーの GIF 画像を生成する

Last updated at Posted at 2014-02-12

概要

  1. 縦横のサイズがそれぞれ 1px で、背景が透明なダミー用の画像が欲しい。
  2. できればコマンドラインでサクッと作りたい。
  3. 余計なツールは入れたくない。

ググればすぐに答えを得られるが、備忘用にメモっておく。

結論

ImageMagick の convert コマンドを使う。

$ convert -size 1x1 xc:none dummy.gif

ImageMagick の identify コマンドで、ちゃんとできたか一応確認しておく。

$ identify dummy.gif
dummy.gif GIF 1x1 1x1+0+0 8-bit sRGB 2c 43B 0.000u 0:00.000

例は GIF だが、他の画像フォーマットでも同じようにできるはず。

動作環境

$ uname -a
Linux desktop-arch 4.8.10-1-ARCH #1 SMP PREEMPT Mon Nov 21 11:55:43 CET 2016 x86_64 GNU/Linux
$ convert --version
Version: ImageMagick 6.9.6-5 Q16 x86_64 2016-11-22 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenCL OpenMP 
Delegates (built-in): bzlib cairo fontconfig freetype gslib jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png ps rsvg tiff webp wmf x xml zlib

ImageMagick は Arch Linux の公式リポジトリにあるパッケージを導入している。

ImageMagick とは

ImageMagick は画像編集のデファクトスタンダード[要出典]なので、多くの環境において導入済みだろう。

引数の xc:none とは

xc:none とは透明の単色画像を指定しているようだ。

まず xc: の部分

擬似ファイル
ImageMagick では画像ファイルの指定部分で、下記の形式を用いることにより作成することができる。|ImageMagick: Formats 参照。
xc:color
colorで塗りつぶされた画像

ImageMagick - くっきー文書館 より

なるほど「擬似ファイル」って分かりやすい。公式ドキュメントも参照してみる。xc: の解説は

An backward compatible alias for the 'canvas:' psuedo-file format, used to create a solid color canvas image.

xc:canvas: のエイリアス。canvas の定義は

Useful to create solid color canvas images. Use -size and -depth to specify the image width, height, and depth. Example canvas color specifications include canvas:red and canvas:#FF0000.
If no color is specified a 'white' canvas image is generated. If no -size is specified a single pixel image of the specified color is generated.

ImageMagick: Formats より

単色画像を生成するのに便利らしい。未確認だが、仕様上は「白色」が既定値のようだ。

指定できる色名

xc:nonenone の部分で色を指定できるようだ。

指定できる色名はドキュメントの Color Names の項を参照。

none 以外にも transparentrgba(0,0,0,0.0) などが透明として扱われるようだ。

16
18
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
16
18