Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Alpha Channel with ImageMagick

Scenario

I would like to save images with alpha transparency as .png and images without alpha transparency as .jpg (even if their original format is .png or .gif). How can I detect whether or not an image has alpha transparency using ImageMagick?

like image 355
brad Avatar asked Apr 05 '10 22:04

brad


People also ask

How do you check if an image has an alpha channel?

To check if the image has an alpha channel, go to the channel dialog and verify that an entry for “Alpha” exists, besides Red, Green and Blue. If this is not the case, add a new alpha channel from the layers menu; Layer+Transparency → Add Alpha Channel.


1 Answers

The ImageMagik command:

identify -format '%[channels]' foo.png  

will print rgba or rgb if there is or is not an alpha channel, respectively.

There could be an alpha channel present with no data in it which wouldn't actually have any transparency, but that is a bit more complicated.

like image 142
msw Avatar answered Sep 21 '22 14:09

msw