[Solved] Exception 420: no decode delegate for this image

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] Exception 420: no decode delegate for this image

Post by tampadavid »

I think this is a bug, but having recently arrived, probably not. Here's my problem: when I pass a variable to $image->Read($string); I get the 420 exception error from line 532 of constitute.c. If I hard-code file names into the $image->Read('picture.png'); then I do not get this error, and the program completes.

I've already realized I can simply write to generic files while iterating a batch of images, over writing as I go, and making the gif animations as I process the other files. BUT! I find it hard to believe the use of $image->Read() does not accept variables.

My understanding is that the method populates an array of images, and then uses those to build the gif. But documentation (that I've found so far...) does not illustrate beyond static filenames as acceptable to the Read() method, and my efforts at using variables, have reliably failed.

I've run a test script in a directory with the png files png1.png and png2.png, which are verified to build into a working gif, from bash/imagemagick. Here's my test script:

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 ($p1, $p2);  # to use static png files for test purposes.  Known OK.
my $x;  # This will be the image file.
my $y = "outputgif.gif";
my $wtf;  # for return code.

$x = Image::Magick->new;

$p1 = "'png1.png'";  # note: these two strings include single quotes.
$p2 = "'png2.png'";  # also, strong (single) quoting $xx in $image->Read('$p1'); 
# prevents variables from expanding.  (??)  (This I do not yet know.)

$x->Set('delay=350');
$x->Set('loop=0');
$wtf=$x->Read($p1);  # does not work, gives 420 exception.
$wtf=$x->Read('png1.png');  # works, but is hard coded into  program.  Huh?
warn $wtf if $wtf;
$wtf=$x->Read($p2);  # does not work, gives 420 exception.
$wtf=$x->Read('png2.png');  # works, but is hard coded into  program.  Huh?
warn $wtf if $wtf;
$wtf=$x->Write($y);
I was surprised to see this NOT fail when the file names were hard-coded. If this is how Image::Magick for perl works, the documentation is sorely lacking. Being new to perl and the Image::Magick module, I started here, http://www.imagemagick.org/script/perl-magick.php, gleaming what I can from the examples. If I can make sense of perl references for arrays and hashes, which I have, I should also be able to make sense of this module's methods. So far as I can tell, $image->Read() has to have its references hard coded, which I do not believe.

I hope this is not a waste of your time. If I could at least get some clarification on the Read() method. Perhaps this is a perl basic, regarding objects and methods, but like I said, I'm new, and working with what I can find out.

David
Last edited by tampadavid on 2014-06-07T09:20:48-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Exception 420: no decode delegate for this image format

Post by snibgo »

I see in another thread viewtopic.php?f=7&t=24811 that someone uses variables in Read, without quite as many quotes as you.

Code: Select all

$inputimage = $ARGV[0];

$outputimage = Image::Magick->new;

$outputimage->Read("$inputimage");
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Exception 420: no decode delegate for this image format

Post by snibgo »

See also examples at:
viewtopic.php?f=7&t=20801&p=83717&hilit=read#p83717
viewtopic.php?f=7&t=19684&p=77577&hilit=read#p77577

I found these with "Advanced search" (top-right of this window), then search for "read" in the perl forum.

[Mod note: I'm also moving this thread to the perl forum.]
snibgo's IM pages: im.snibgo.com
tampadavid
Posts: 13
Joined: 2014-06-02T13:11:51-07:00
Authentication code: 6789

Re: Exception 420: no decode delegate for this image format

Post by tampadavid »

Thank you for the reply, and the search results. I looked for relevant stuff and did not find: perl Image::Magick Read() method on GNU/Linux, with 420 error. (Yeah, I know, it's 420 somewere... :lol: ) I read throught constitute.c last night, and see that the methods called ReadImage, rather than Read.

Code: Select all

MagickExport Image *ReadImage(const ImageInfo *image_info,
  ExceptionInfo *exception)
and

Code: Select all

MagickExport Image *ReadImages(const ImageInfo *image_info,
  ExceptionInfo *exception)
Singular and plural, and wonder if ReadImage(s) is the proper way to reference these methods.(?) I do not know, that's why I am here. I assume too that Read() is an alias for ReadImage(s).(?) Ditto.

I am necessarily in "Monkey Seeing Monkey Doing" mode, until I learn more, by seeing and doing.

Since this has been moved to the perl forum, I have an additional question of path errors. The filenames I pass to the Read() method include relative path information, ie: './pngs/<filename>.png' './pngs/' is added to the filename earlier, when creating the pngs via IM, from large source jpeg files.

Thanks for the help. The hardest thing about discovering answers is knowing the problem.

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

Re: Exception 420: no decode delegate for this image format

Post by zemlik »

this works

Code: Select all

#!/bin/perl
use warnings;
use strict;
use Image::Magick;
my $image=Image::Magick->new;
my $giff=Image::Magick->new;
my @pics=Image::Magick->new;
@pics=qw/a1.png b1.png c1.png d1.png e1.png /;
$giff=$image->Read($pics[0],$pics[1],$pics[2],$pics[3],$pics[4]);
$giff=$image->Write("output2.gif");



tampadavid
Posts: 13
Joined: 2014-06-02T13:11:51-07:00
Authentication code: 6789

Re: Exception 420: no decode delegate for this image format

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