60

I want to create a .png file which is just a solid color.

This must be easy to do using ImageMagick but I can't figure out the problem:

C:\tmp>convert -size 8x16 -stroke black -fill black -draw "rectangle 0,0,8,16" black.png
Magick: missing an image filename `black.png' @ error/convert.c/ConvertImageComm
and/3016.
Jason S
  • 184,598
  • 164
  • 608
  • 970

3 Answers3

91

Obviously there can be more options, like borders and etc, but if you just want an image of width x height of a given hex color, it's pretty straight forward.

Here's all it takes to make an 100x100 image of a solid dark red:

convert -size 100x100 xc:#990000 whatever.png
Mike Flynn
  • 2,153
  • 16
  • 22
  • great, thanks! (btw, where's the docs for xc: and what does it stand for? I can't seem to find them via google) – Jason S Oct 14 '11 at 20:20
  • 4
    It's a shortcut for color codes. You can put hex, rgb() or even a color name in there. I'm honestly not sure what it stands for though. More info: http://www.imagemagick.org/script/color.php – Mike Flynn Oct 15 '11 at 00:19
  • 6
    You can also use rgba values `convert -size 100x100 xc:rgba\(255,0,0,0.4\) whatever.png` – luk3thomas Jan 15 '14 at 19:36
  • 2
    This is what I love about unix tools. I was going to make a python program for this but then I remembered imagemagick. Nothing beats a bash one-liner – Rombus Jul 04 '16 at 19:25
  • @luk3thomas does that make the `whatever.png` semi-transparent? I tried command (in graphicsmagick) and although the command succeeded, it created a solid red rectangle. – CMCDragonkai Jul 31 '16 at 11:41
  • 3
    The `xc:#...` is a pseudo-image format; an alias for `canvas:#...` -- look at the "Pseudo-image Formats" section of http://www.imagemagick.org/script/formats.php – user295691 Oct 27 '16 at 15:33
  • 1
    On Unix-like systems, hex colors and rgb(...) colors must be enclosed in quotes. – fmw42 Aug 29 '19 at 15:55
10

Note that for rgb and rgba values, you need to escape the parentheses. Building on @Mike Flynn and @luk3thomas (who correctly escapes the color code):

convert -size 100x100 xc:rgb\(0,255,0\) whatever.png
convert -size 100x100 xc:rgba\(0,255,0, 0.4\) whatever.png
DaveL17
  • 1,673
  • 7
  • 24
  • 38
4

In Mac

convert -size 100x100 xc:"#8a2be2" blue@2x.png
dengST30
  • 3,643
  • 24
  • 25