imagemagick: create a .png file which is just a solid rectangle

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.

Solution 1:

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

Solution 2:

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

Solution 3:

In Mac

convert -size 100x100 xc:"#8a2be2" [email protected]