Page 1 of 1

Detecting Transparency?

Posted: 2015-03-23T14:58:08-07:00
by dudeman
Hi,

I have a pretty simple application that i've inherited maintenance of. The app keeps a directory of images that can be searched based on a number of stored data points. I've been ask to add a boolean flag if an image has transparency. All the images are png, jpeg, and maybe some gifs. I tried using matte() like this:

Code: Select all

  my $image = Image::Magick->new;
  $image->read($directory.$file_name);

  return $image->matte();
But, I got the following error:

Code: Select all

Can't locate auto/Image/Magick/matte.al in @INC
I am using perl and Mojolicous on a Mac with Yosemite. I didn't install Image::Magick so from cpan, or the libraries on my mac, so I'm assuming it's a standard install.

Any ideas?

Thanks,

Re: Detecting Transparency?

Posted: 2015-03-23T17:30:42-07:00
by snibgo
That doesn't look like an error message from ImageMagick.

I know nothing about perl and Mojolicous etc.

From the command line ...

Code: Select all

convert in.png -format %[opaque] info:
... will return "true" if the image is fully opaque; otherwise "false".

Re: Detecting Transparency?

Posted: 2015-03-24T10:28:50-07:00
by dudeman
Awesome! You pointed me in the right direction. FYI I got this perl code from stack overflow. It seems to do exactly what I want. Found it thanks to snibgo.

Code: Select all

#!/usr/bin/perl
use warnings;
use strict;
use Image::Magick;
my $image = Image::Magick->new();
$image->Read($ARGV[0]);
my $a = $image->Get('%[opaque]');
print $a;
http://stackoverflow.com/questions/2630 ... 5#26305875