Detecting Transparency?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
dudeman
Posts: 2
Joined: 2015-03-23T14:46:38-07:00
Authentication code: 6789

Detecting Transparency?

Post 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,
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Detecting Transparency?

Post 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".
snibgo's IM pages: im.snibgo.com
dudeman
Posts: 2
Joined: 2015-03-23T14:46:38-07:00
Authentication code: 6789

Re: Detecting Transparency?

Post 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
Post Reply