views:

37

answers:

1

What is the smartest way to find out if a PNG has transparency or not in Ruby? Is it OK if I just check if there's an alpha-channel? If yes: How do I check for an alpha-channel?

I'm writing a script that will convert all PNGs without transparency into smaller JPGs.

Thanks a lot for your help!

+2  A: 

Checking the alpha channel seems the most sensible thing to do. Is it safe to assume you are using RMagick? did you read the documentation?

>> require 'RMagick'
>> image = Magick::Image.read("a.png").first
>> image.alpha?
=> true

http://www.imagemagick.org/RMagick/doc/image1.html#alpha_q

tokland
Thanks for the hint and the link! In my case, it seems that all PNGs do have an alpha-channel. Excuse my lame question, but is it possible to have a non-transparent PNG and still have an alpha-channel? That would mean that checking for an alpha-channel is not enough in my case.
Javier
you may link that special image in the question.
tokland