Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

imagemagick

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.
like image 891
Jason S Avatar asked Oct 14 '11 18:10

Jason S


3 Answers

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
like image 161
Mike Flynn Avatar answered Nov 04 '22 22:11

Mike Flynn


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
like image 20
DaveL17 Avatar answered Nov 04 '22 23:11

DaveL17


In Mac

convert -size 100x100 xc:"#8a2be2" [email protected]
like image 3
dengST30 Avatar answered Nov 04 '22 22:11

dengST30