51

How to create a blank new image in Imagemagick via command line?

Using -background doesn't work:

$ convert -size 800x800 -background white x.png
convert: no images defined `x.png' @ error/convert.c/ConvertImageCommand/3257.
qubodup
  • 8,687
  • 5
  • 37
  • 45

2 Answers2

81

White background

convert -size 800x800 xc:white white.png

xc: used to mean "X Constant Image" but now is just a shorthand for canvas:. This means you can also use:

convert -size 800x800 canvas:white white.png

and because "white" is the default value if no color is provided, you can also use:

convert -size 800x800 xc: white.png
convert -size 800x800 canvas: white.png

Transparent background

If by "blank" you mean "transparent", just use that word as the color:

convert -size 800x800 xc:transparent transparent.png

Answer made possible by ImageMagick v6 Examples and How to create a new image?

qubodup
  • 8,687
  • 5
  • 37
  • 45
  • 9
    Actually, you can do it even more simply by specifying the size with the canvas... `convert xc:[800x800\!] white.png` or `convert xc:lime[800x800\!] lime.png`. – Mark Setchell Sep 15 '16 at 07:59
  • 8
    @MarkSetchell although from a human end user perspective, I would say that is less simple. I use `-size` all the time. Learning additionally `canvas:green` is the least amount of new information between these two options. – Jan Kyu Peblik Oct 02 '18 at 16:28
  • 3
    How cn I do it without having it assign the PNG a greyscale color profile? – theonlygusti Dec 16 '20 at 11:45
  • theonlygusti, I think @cjonasw have answered this [here](https://stackoverflow.com/a/67427236/5623661) in this very page. – dani 'SO learn value newbies' Jan 16 '23 at 22:50
9

You need to supply PNG24, PNG8 or PNG32 prefix if planning to use this canvas to layer colour images over. Without it, it creates a Grey colour space. I used 32, as I need "varying degrees of transparency for each pixel" (pixel art)

convert -size 800x800 canvas:transparent PNG32:canvas.png

For more about PNG types see this link.

cjonasw
  • 488
  • 3
  • 7