Results 1 to 5 of 5

Thread: How to detect that a PNG has an alpha channel from command line?

  1. #1
    Member m^2's Avatar
    Join Date
    Sep 2008
    Location
    Ślůnsk, PL
    Posts
    1,611
    Thanks
    30
    Thanked 65 Times in 47 Posts

    How to detect that a PNG has an alpha channel from command line?

    The first thing that I tried was Image Magick. Weirdly, it's 'identify' tool always shows that PNGs are 8-bit ones.
    I have a lot of PNGs and want to find the ones with alpha to split the transparency layer out.

  2. #2
    Programmer schnaader's Avatar
    Join Date
    May 2008
    Location
    Hessen, Germany
    Posts
    565
    Thanks
    216
    Thanked 200 Times in 93 Posts
    You could give this one a try (from Stack Overflow):

    Code:
    identify -format '%[channels]' foo.png
    This should print "rgba" if an alpha channel is present, "rgb" else.
    http://schnaader.info
    Damn kids. They're all alike.

  3. #3
    Member m^2's Avatar
    Join Date
    Sep 2008
    Location
    Ślůnsk, PL
    Posts
    1,611
    Thanks
    30
    Thanked 65 Times in 47 Posts
    It works, thank you.

  4. #4
    Member caveman's Avatar
    Join Date
    Jul 2009
    Location
    Strasbourg, France
    Posts
    190
    Thanks
    8
    Thanked 62 Times in 33 Posts
    pngcheck displays if a picture is in 32-bits or 24-bits mode the same goes for grey+alpha (16-bits) and gray (8-bits, 4 bits, 2-bits and even 1-bit), for instance:
    OK: xx.png (210x210, 32-bit RGB+alpha, non-interlaced, 71.9%).
    OK: yy.png (559x702, 24-bit RGB, non-interlaced, 38.9%).

  5. #5
    Member Karhunen's Avatar
    Join Date
    Dec 2011
    Location
    USA
    Posts
    91
    Thanks
    2
    Thanked 1 Time in 1 Post
    There is also a tool included called pngsplit, which dumps the IDATs and other chunks, but I am looking for a tool that would split a PNG into independent PNGs capable of
    being recognized by Precomp. Specifically, I want to save RGBA pngs to grayscale PNG for each channel and be able to recombine them:
    convert globe_x.png -channel G -separate 01grn.png // convert globe_x.png -channel R -separate 00red.png // convert globe_x.png -channel B -separate 02blu.png // convert -alpha extract globe_x.png 04alpha.png
    But combining them does not result in original image: convert 00red.png 01grn.png 02blu.png -combine copy_opacity x-04alpha.png -composite out.png
    Files attached.
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	00red.png 
Views:	297 
Size:	277 Bytes 
ID:	2111   Click image for larger version. 

Name:	01blu.png 
Views:	304 
Size:	19.2 KB 
ID:	2112   Click image for larger version. 

Name:	02grn.png 
Views:	318 
Size:	40.0 KB 
ID:	2113   Click image for larger version. 

Name:	04alpha.png 
Views:	376 
Size:	7.9 KB 
ID:	2114   Click image for larger version. 

Name:	globe_x.png 
Views:	981 
Size:	85.7 KB 
ID:	2115  

    Click image for larger version. 

Name:	out.png 
Views:	317 
Size:	122.7 KB 
ID:	2116  

Similar Threads

  1. UCLC (Ultimate Command Line Compressors) Benchmarks
    By osmanturan in forum Data Compression
    Replies: 2
    Last Post: 4th September 2015, 12:30
  2. Replies: 39
    Last Post: 10th April 2014, 23:26
  3. command-line calculator for Windows?
    By Alexander Rhatushnyak in forum The Off-Topic Lounge
    Replies: 5
    Last Post: 30th January 2012, 00:40
  4. a small plea for the command line compression developers
    By SvenBent in forum Data Compression
    Replies: 2
    Last Post: 14th June 2008, 03:51
  5. DARK - a new BWT-based command-line archiver
    By encode in forum Forum Archive
    Replies: 138
    Last Post: 23rd September 2006, 22:42

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •