[Solved] perl Image::Magick Read exception 420 on png files.

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
tampadavid
Posts: 13
Joined: 2014-06-02T13:11:51-07:00
Authentication code: 6789

[Solved] perl Image::Magick Read exception 420 on png files.

Post by tampadavid »

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! :lol: ), 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
Last edited by tampadavid on 2014-06-07T09:19:48-07:00, edited 1 time in total.
tampadavid
Posts: 13
Joined: 2014-06-02T13:11:51-07:00
Authentication code: 6789

Re: perl Image::Magick Read exception 420 on png files.

Post by tampadavid »

Iv'e tried to iterate through, feeding Read() one filename at a time, and it fails with 420, same as above.

Does anyone out there have an actual working perl script that creates a gif animation from a sequence of png files? I'd like to see it.

I have not found better documentation so far. According to what I've found, this should work. IE:

#!/usr/local/bin/perl
use Image::Magick;

my($image, $x);

$image = Image::Magick->new;
$x = $image->Read('girl.png', 'logo.png', 'rose.png');
warn "$x" if "$x";

$x = $image->Crop(geometry=>'100x100+100+100');
warn "$x" if "$x";

$x = $image->Write('x.png');
warn "$x" if "$x";

As taken from: http://www.imagemagick.org/script/perl-magick.php

$x = $image->Read('girl.png', 'logo.png', 'rose.png'); seems to accept a single quoted, comma separated list of filenames. My list of filenames include path information, which I would not expect to be a problem. These files were written just prior to their sub-directory by Image::Magick.

Or is it so obvious, that Image::Magick cannot create a gif animation from png source files? It certainly can from bash. That was the first thing I did, as a proof of code. "So jump into bash." you perhaps are saying right now? Well, if Image::Magick is not going to work, perhaps I'll have too.

I'd like to think instead, that I am making a really stupid error, rather than Image::Magick is not working. I wish I had better documentation. I'll have to put some out here when it is all said and sorted. Your help on this is greatly appreciated.

David
zemlik
Posts: 38
Joined: 2014-03-05T06:12:01-07:00
Authentication code: 6789

Re: perl Image::Magick Read exception 420 on png files.

Post by zemlik »

I'm just learning perl. I am doing something similar as in previous post. I am reading file names from a .csv file and combining them all per line. There is something that I do not understand in that I can read all of the fields in the lines and put them in an array and print the names to screen but for some reason I cannot neither read or combine or write the last image although previously I have been able to.. I thought it must be an issue in the loops but I cannot see it. I have got around it by having a blank, transparent.png as the last image.
[edit]
I think this is something to do with wrong list and scalar context where the last element is ignored but I can't find where I read it.

I don't know how to do a gif in Image::Magick but I will have a look when I have done current task,understanding making images transparent.
Last edited by zemlik on 2014-06-06T00:45:33-07:00, edited 1 time in total.
tampadavid
Posts: 13
Joined: 2014-06-02T13:11:51-07:00
Authentication code: 6789

Re: perl Image::Magick Read exception 420 on png files.

Post by tampadavid »

I believe when you specify it by filename extention: <filename>.gif, you are instructing Image::Magick to save as a gif. Of course, Mine stuff is still not working, so, if anyone knows better, let us know.
zemlik
Posts: 38
Joined: 2014-03-05T06:12:01-07:00
Authentication code: 6789

Re: perl Image::Magick Read exception 420 on png files.

Post by zemlik »

the example at http://www.imagemagick.org/script/perl-magick.php works ok.
with .gif and .png
this is the same thing, which works

Code: Select all

#!/bin/perl
use warnings;
use strict;
use Image::Magick;
my $image=Image::Magick->new;
my $giff=Image::Magick->new;
$giff=$image->Read('a1.png','b1.png','c1.png','d1.png','e1.png');
$giff=$image->Write("outputpng.gif");
tampadavid
Posts: 13
Joined: 2014-06-02T13:11:51-07:00
Authentication code: 6789

Re: perl Image::Magick Read exception 420 on png files.

Post by tampadavid »

Marking this solved.

It is a perl syntax issue. Thus:

Code: Select all

#!/usr/bin/env perl

#perl-jsiiw-Read-fail.pl: testing program for the Image::Magick Read method.

use strict;
use warnings;
use Image::Magick;

my ($x, $y, $z);  # This will be the image file.
my $wtf;  # for return code.
my ($v1, $v2);

# other code omitted here, not relevant.....

# This time, passing an array, not a scalar variable.  This is >not< documented at imagemagick.org.
my @A1 = ("./stamped/516A_700x700.png", "./stamped/516B_700x700.png");#list.
$v2 = "./ss-gifs/516C.gif";
$y = Image::Magick->new;
$y->Set('delay=>350');
$y->Set('loop=>0');
$wtf=$y->Read(@A1);  # <<<<<<  this fixes the error, and works very well.
warn $wtf if $wtf;
$wtf=$y->Write($v2);
undef $y;
My mistake, though it is not really a mistake, is in missing the global (globbing) implication of the term "list" in the documentation. It is a simple matter, and a matter of simple competence, since this document is supposed to be for those (like me) who are just learning, to include an example such as this one shown above. I feel that such an explication should be added to: http://www.imagemagick.org/script/perl-magick.php precisely because folks like myself do not know what to do, yet. I suggest:

Code: Select all

 $x = $image->Read('girl.png', 'logo.png', 'rose.png');  # list && "list like" -- like an array.
# my @array = ('girl.png', 'logo.png', 'rose.png');
#$x = $image->Read(@array);
This makes it clear to noobs like myself, who are only a couple of weeks into perl. Syntax is utterly arbitrary, and until one has time with the protocols, there is nothing obvious about it. Noob documentation does well to remember that.

Now to sort the label issue...
Post Reply