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 convert command is built into the main magick binary. You can use magick or magick convert interchangeably 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.

Key Parameters Explained