Ruby: Find non-transparent PNG and convert into JPG
-
28-09-2019 - |
Pergunta
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!
UPDATE: In the meantime I've written that script and you can find it at Github.
Solução
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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow