[Solved] perl Image::Magick Read exception 420 on png files.
Posted: 2014-06-03T08:34:31-07:00
I'm writing a program to manage images, taking a very large source image, and producing HD sized pngs, 700px ish "slider" images, and building gifs from pairs of images, that are question/answer in nature. The gif files are for the display page on a website. I am coding in perl 5.14.2, using imagemagick 6.6.9-7 (bummer too, 6.6.6 was a hell of a release! ), working on Ubuntu 12.04 LTS, all up to date.
I am using Image::Magick in other parts of this program (and other programs too) without any difficulty, and until now, I have never had this type of problem using IM.
Here are my perl use settings:
use strict;
use warnings;
use Image::Magick;
The error is happening in the Read() method of Image::Magic:
my $wtf = $giffile->Read($giflist);
warn $wtf if $wtf;
and $giflist is from:
push @{$gifhash{$keyvalue}}, "'${stampeddir}/${filelabel}'"; <<< note this string includes the single quotes, hard to see outside a courier font.
...
...
foreach $level1 (keys %gifhash) {
my @gifarray = @{$gifhash{$level1}};
my $giflist = join ', ', sort @gifarray;
I've verified the list with:
print "\$giflist: $giflist\n"; which produces:
$giflist: './stamped/519A-700x700.png', './stamped/519B-700x700.png'
$giflist: './stamped/518A-700x700.png', './stamped/518B-700x700.png'
and so forth. $giflist holds a string of single quoted, comma separated file names, that exists. These files are pngs created by imagemagick just prior, and are properly pathed and permitted. This is verified by the exception code: 420, which is an error after a path/access sanity check, according to the source code (constitute.c):
if ((magick_info == (const MagickInfo *) NULL) ||
(GetImageDecoder(magick_info) == (DecodeImageHandler *) NULL))
{
if (IsPathAccessible(read_info->filename) != MagickFalse) // aka filename is ok.
(void) ThrowMagickException(exception,GetMagickModule(),
MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'",
read_info->magick);
else
ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
read_info->filename);
read_info=DestroyImageInfo(read_info);
return((Image *) NULL);
}
The printed error is:
Exception 420: no decode delegate for this image format `'./stamped/518A-700x700.png', './stamped/518B-700x700.png''
Which does not make sense to me. my $wtf = $giffile->Read($giflist); is supposed to be list friendly, according to documentation, per http://www.imagemagick.org/script/perl-magick.php:
Method: Read, Parameters: one or more filenames, Return Value: the number of images read, Description: read an image or image sequence
I considered the possibility of path issues, or perhaps the method and only work in pwd, but that is not the error, and in fact, we're clear of the pathing check:
if (IsPathAccessible(read_info->filename) != MagickFalse) // Just love the double negatives.... if filename sane, then... is what this means.
(void) ThrowMagickException(exception,GetMagickModule(),
MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'",
read_info->magick);
If it turns out that the Read() method in Image::Magick for perl is NOT list friendly, then please update the documentation. I cannot believe it would not be, but then this isn't working.
And again, it is probably some small detail that is too un-important for me to notice, that has this failing. That's why I ask.
David
I am using Image::Magick in other parts of this program (and other programs too) without any difficulty, and until now, I have never had this type of problem using IM.
Here are my perl use settings:
use strict;
use warnings;
use Image::Magick;
The error is happening in the Read() method of Image::Magic:
my $wtf = $giffile->Read($giflist);
warn $wtf if $wtf;
and $giflist is from:
push @{$gifhash{$keyvalue}}, "'${stampeddir}/${filelabel}'"; <<< note this string includes the single quotes, hard to see outside a courier font.
...
...
foreach $level1 (keys %gifhash) {
my @gifarray = @{$gifhash{$level1}};
my $giflist = join ', ', sort @gifarray;
I've verified the list with:
print "\$giflist: $giflist\n"; which produces:
$giflist: './stamped/519A-700x700.png', './stamped/519B-700x700.png'
$giflist: './stamped/518A-700x700.png', './stamped/518B-700x700.png'
and so forth. $giflist holds a string of single quoted, comma separated file names, that exists. These files are pngs created by imagemagick just prior, and are properly pathed and permitted. This is verified by the exception code: 420, which is an error after a path/access sanity check, according to the source code (constitute.c):
if ((magick_info == (const MagickInfo *) NULL) ||
(GetImageDecoder(magick_info) == (DecodeImageHandler *) NULL))
{
if (IsPathAccessible(read_info->filename) != MagickFalse) // aka filename is ok.
(void) ThrowMagickException(exception,GetMagickModule(),
MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'",
read_info->magick);
else
ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
read_info->filename);
read_info=DestroyImageInfo(read_info);
return((Image *) NULL);
}
The printed error is:
Exception 420: no decode delegate for this image format `'./stamped/518A-700x700.png', './stamped/518B-700x700.png''
Which does not make sense to me. my $wtf = $giffile->Read($giflist); is supposed to be list friendly, according to documentation, per http://www.imagemagick.org/script/perl-magick.php:
Method: Read, Parameters: one or more filenames, Return Value: the number of images read, Description: read an image or image sequence
I considered the possibility of path issues, or perhaps the method and only work in pwd, but that is not the error, and in fact, we're clear of the pathing check:
if (IsPathAccessible(read_info->filename) != MagickFalse) // Just love the double negatives.... if filename sane, then... is what this means.
(void) ThrowMagickException(exception,GetMagickModule(),
MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'",
read_info->magick);
If it turns out that the Read() method in Image::Magick for perl is NOT list friendly, then please update the documentation. I cannot believe it would not be, but then this isn't working.
And again, it is probably some small detail that is too un-important for me to notice, that has this failing. That's why I ask.
David