How to Create a Colored Blank Canvas in ImageMagick?
This article provides a quick overview and practical examples of how
to generate a blank canvas with a specific background color using the
ImageMagick convert command. You will learn the exact
syntax required to define the canvas dimensions, choose a custom color,
and save the output in your desired image format.
The Basic Command Syntax
To create a solid color blank canvas from scratch, you use the
-size flag to define the dimensions and the
xc: prefix (which stands for “X Constant Image”) followed
by your chosen color.
The standard syntax is:
magick convert -size [width]x[height] xc:[color] [output_file]
Note: In ImageMagick v7 and later, the
convertcommand is built into the mainmagickbinary. You can usemagickormagick convertinterchangeably depending on your version.
Practical Examples
Here are a few common ways to use the command depending on how you want to specify your color:
1. Using Named Colors
ImageMagick recognizes hundreds of standard color names like
white, black, red,
blue, or canvas.
magick convert -size 800x600 xc:blue blue_canvas.png
2. Using Hex Codes
If you need a specific brand color or exact digital shade, you can
pass a hex code. Be sure to wrap the color in quotes so your terminal
doesn’t misinterpret the # symbol.
magick convert -size 1920x1080 xc:"#33495e" dark_blue_canvas.jpg
3. Using RGB or RGBA Values
For precise color control or to add transparency, you can use RGB or RGBA (which includes an alpha channel for transparency) values.
- Solid Color (RGB):
magick convert -size 500x500 xc:"rgb(255,100,50)" rgb_canvas.png - Transparent Canvas (RGBA):
magick convert -size 400x400 xc:"rgba(0,0,0,0.0)" transparent_canvas.png
Key Parameters Explained
-size 800x600: Sets the width to 800 pixels and the height to 600 pixels.xc:color: Fills the defined canvas size with the specified color. You can also usecanvas:coloras an alternative alias.output.png: The final filename. ImageMagick automatically determines the file format based on the extension you provide (e.g.,.png,.jpg,.gif).