Is there a way to find all PNG files in a folder that have transparent pixels

I have a couple thousand PNGs, all of them probably support the alpha channel but only some of them actually use it (Only some of them actually have transparent pixels).

Is there any way at all for me to quickly find all such files?

Asked By: Cestarian

||

Use netpbm:

pngtopnm -alpha filename.png | pgmhist

If there’s a row starting with value "0" the image contains fully transparent pixels

If there’s a number row other than value "255" the image contains partially transparent pixels.

so put that in a for loop.

for file in *.[pP][Nn][Gg] 
do
  pngtopnm -alpha -- "$file" | pgmhist | grep -q '^ *0 ' && echo "$file" contains transparent pixels.
done
Answered By: Jasen

Found a way using imagemagick.

identify -format '%[opaque]' filename.png

so where ‘$@’ is the path to your image:

#!/bin/bash
case $(identify -format '%[opaque]' "$@") in 
    [Ff]alse) echo "Image has transparent pixels";;
    [Tt]rue) echo "Image has no transparent pixels";;
    *) echo "Error"
esac
Answered By: Cestarian
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.