Skip to content

Instantly share code, notes, and snippets.

@t-mat
Last active January 12, 2025 21:39
Show Gist options
  • Save t-mat/c4b042ff50c924bc3c41b078d1a0dd80 to your computer and use it in GitHub Desktop.
Save t-mat/c4b042ff50c924bc3c41b078d1a0dd80 to your computer and use it in GitHub Desktop.
ImageMagick basics: color component separation and compose

Separate each color component, save them as a PNG32 (R8G8B8A8).

magick input.png -channel R -separate PNG32:component_r.png
magick input.png -channel G -separate PNG32:component_g.png
magick input.png -channel B -separate PNG32:component_b.png
magick input.png -channel A -separate PNG32:component_a.png

Reconstruct a image from separated components, save it as a PNG32.

magick component_r.png \
       component_g.png -compose CopyGreen -composite \
       component_b.png -compose CopyBlue  -composite \
       component_a.png -alpha off -compose CopyAlpha -composite \
       PNG32:reconstruct.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment