Attribute <image> fails type constraint

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

Attribute <image> fails type constraint

Post by marc557 »

I am getting his error when I used Graphics::DZI which must also use Image::Magick

Attribute <image> does not pass the type constraint because: Validation failed for 'Image::Magick' with value record-image.jpg <not isa Image::Magick> at ...

What am I doing wrong?

Thanks,

Marc

This is my code

Code: Select all

use Graphics::DZI;
use strict;
use warnings;

my $image = "record-image.jpg";
my $overlap = "0";
my $tilesize = "256";
my $format = "jpeg";

my $dzi = Graphics::DZI->new(overlap  => $overlap,
                             image    => $image,
                             tilesize => $tilesize
                               );

write_file ("xxx.xml", $dzi->descriptor);
$dzi->iterate ();
exit;
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Attribute <image> fails type constraint

Post by snibgo »

From the documentation http://search.cpan.org/dist/Graphics-DZ ... ics/DZI.pm the image parameter needs to be an Image::Magick object, not a string.
snibgo's IM pages: im.snibgo.com
marc557
Posts: 4
Joined: 2014-11-06T18:51:03-07:00
Authentication code: 6789

Re: Attribute <image> fails type constraint

Post by marc557 »

But that's the name of the image. How do I specify an image without a name?

Thanks,

Marc
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Attribute <image> fails type constraint

Post by snibgo »

In computer languages, objects have types. For example: string, integer, floating-point, image. I suggest you read a programming tutorial.
snibgo's IM pages: im.snibgo.com
marc557
Posts: 4
Joined: 2014-11-06T18:51:03-07:00
Authentication code: 6789

Re: Attribute <image> fails type constraint

Post by marc557 »

Snibdgo,

I realize that it is related to the data type. How do I specify an image type in this case?

Thanks,

Marc
marc557
Posts: 4
Joined: 2014-11-06T18:51:03-07:00
Authentication code: 6789

Re: Attribute <image> fails type constraint

Post by marc557 »

I modified my code as show in red as it still fails. Can somebody help me? Thanks, Marc

use strict;
use warnings;
use Graphics::DZI;
use Image::Magick;

my $image = Image::Magick->new;
my $x = $image->Read("record-image.jpg");


#my $image = "record-image.jpg";
my $overlap = "0";
my $tilesize = "256";
my $format = "jpg";

my $dzi = Graphics::DZI->new(image => $x,
overlap => $overlap,
tilesize => $tilesize,
);

#write_file ("xxx.xml", $dzi->descriptor);
$dzi->iterate ();
# !!! this does only display the tiles on the screen
# !!! see Graphics::DZI::Files for a subclass which
# !!! actually writes to files
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Attribute <image> fails type constraint

Post by snibgo »

Sorry, I don't know Perl and I've never heard of DZI. But the documentation http://www.imagemagick.org/script/perl-magick.php#read tells me that Read() returns the number of images read. $x becomes a number, not an image. Passing a number instead of an image to Graphics::DZI->new() won't work.

There are plenty of examples in this forum that will, I think, work for you.
snibgo's IM pages: im.snibgo.com
Post Reply