Keep/discard alfa depending on opacity

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
elmimmo
Posts: 26
Joined: 2011-02-02T05:42:42-07:00
Authentication code: 8675308

Keep/discard alfa depending on opacity

Post by elmimmo »

I want to batch convert multiple PSD to a TIFF files without layers. If I am not mistaken, I can just grab the composite version of the PSD by appending [0] to its filename, but then, regarding the alpha, is there a way to programmatically keep it or discard it depending on whether there actually exists any non-opaque pixel in the image at all or discard it if not? Even better, could that test ignore the outmost n-pixels in the four edges of the image?
elmimmo
Posts: 26
Joined: 2011-02-02T05:42:42-07:00
Authentication code: 8675308

Re: Keep/discard alfa depending on opacity

Post by elmimmo »

I found that I can query if the composite PSD "is image fully-opaque?" with

Code: Select all

identify -format %[opaque] ${PSD}[0]
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Keep/discard alfa depending on opacity

Post by snibgo »

Yes. I would do it in a script. Convert it, and test for %[opaque] in the result. If "True" then convert again with "-alpha off".

If you want to ignore some pixels for the test, then crop or shave the image.
snibgo's IM pages: im.snibgo.com
Post Reply