v7.1.2-34 Latest Stable Release

Color Management

Master color management in ImageMagick. Learn how sRGB, linear RGB, grayscale, and ICC profiles affect image processing, with practical command examples for accurate conversions and channel handling.

quickstart.sh
# Install via your favorite Package Manager
$ brew install imagemagick
# Convert PNG to WebP with compression
$ magick input.png -quality 85 output.webp
# Resize image maintaining aspect ratio
$ magick input.jpg -resize 800x600^ output.jpg

Due to the standardization of sRGB on the Internet, most image formats use sRGB as the default working color space. If an image's color space is unknown and it is an 8- to 16-bit format, assuming sRGB—and non-linear grayscale—is a safe choice. These assumptions are overridden if the file includes specific color space or gamma metadata, if you apply explicit color profiles, or if you use the -set option.

Color Profiles and Linear Adjustments

For images without a profile or color space declaration, ImageMagick defaults to non-linear sRGB. Because most image processing algorithms perform best in a linear color space, it is often prudent to convert to linear color or remove the gamma function before applying heavy operations. For example:

$ magick myimage.jpg -colorspace RGB -resize 200% -colorspace sRGB mybigimage.jpg

Declaring vs. Converting Linear RGB

To declare that an image is linear RGB rather than sRGB without altering its actual pixel data, use the -set option:

$ magick myimage.png -set colorspace RGB myRGBimage.png

Note: Declaring an image as linear only updates the metadata and leaves pixel data untouched, whereas converting actually changes the pixel values. Verbose file information will list the color space as RGB, though this only works on formats that support distinguishing linear vs. non-linear metadata (such as PNG and GIF). For JPG or TIF output formats, you must include an appropriate color profile to correctly embed linear color awareness.

Grayscale Conversions

Converting color images to grayscale normally yields non-linear gray. To generate linear gray instead, use the -set, -intensity, or -grayscale options:

$ magick myimage.png -colorspace LinearGray myRGBimage.png
$ magick myimage.png -colorspace RGB -colorspace Gray myRGBimage.png
$ magick myimage.png -intensity Rec709luminance -colorspace gray myRGBimage.png
$ magick myimage.png -grayscale Rec709luminance myRGBimage.png

Note: LinearGray is available as of ImageMagick 6.9.9-29 and 7.0.7-17.

Channel Separation and Recombination

When separating channels from an sRGB image, the default output produces non-linear grayscale images. If you wish to keep them as linear grayscale channels for processing, configure the color space beforehand:

$ magick myimage.png -colorspace RGB -separate myimage_channels_%d.png

When performing intermediate processing between separation and recombination, tracking the color space is crucial:

$ magick myimage.png -separate myimage_channels_%d.png
$ magick myimage_channels_*.png -combine myimage2.png

In the example above, channels are non-linear, and -combine defaults to assuming non-linear channels, resulting in an output identical to the input.

To separate into linear grayscale channels, process them, and then recombine them back into a non-linear color image, use this pattern:

$ magick myimage.png -set colorspace RGB -separate myimage_channels_%d.png
$ magick myimage_channels_*.png -set colorspace RGB -combine -colorspace sRGB myimage2.png

Cross-Color Space Handling (e.g., HSL)

The following commands handle non-linear vs. linear channel workflows when converting between sRGB and HSL:

$ magick myimage.png -colorspace HSL -separate myimage_channels_%d.png
$ magick myimage_channels_*.png -set colorspace HSL -combine -colorspace sRGB myimage2.png

$ magick myimage.png -set colorspace RGB -colorspace HSL -separate myimage_channels_%d.png
$ magick myimage_channels_*.png -set colorspace HSL -combine -colorspace RGB -set colorspace sRGB myimage2.png

Format Support and Linear Color Creation

While most image formats (like JPEG and PNG) assume an sRGB color space, some support only linear RGB (such as EXR, DPX, CIN, and HDR), linear GRAY, or CMYK (like JPG, but not PNG). Occasional formats also support LAB (CieLAB) like TIFF, PSD, JPG, and JP2. For further details, consult the Colorspace and Supported Formats pages.

When specifying individual colors using rgb(...) or hex notation, they are interpreted as non-linear sRGB. If you need to explicitly create linear colors, use the icc-color(rgb,r,g,b) syntax (where components range from 0 to 1). See the Color page for more information.