Page 1 of 1

problem running composite - exception 410 [solved]

Posted: 2011-06-26T11:53:34-07:00
by symulant
I want to move the code from bash to Perl

Code: Select all

#!/bin/bash
composite -compose plus image.png mask.png image_mask0.png
Bash script works fine.

I tried three times to write it using Perl and the Image:: Magick:

Code: Select all

#!/usr/bin/perl -w
use strict;
use Image::Magick;

my $im_x;
$im_x=Image::Magick->new;

my $x=$im_x->Composite(compose=>"Plus", image=>"image.png", mask=>"mask.png");
warn "$x" if "$x";

$im_x->Write("image_mask1.png");

undef $im_x;

Code: Select all

#!/usr/bin/perl -w
use strict;                                                                                                                                         
use Image::Magick;                                                                                                                                  
                                                                                                                                                    
my $im_x;                                                                                                                                           
$im_x=Image::Magick->new;                                                                                                                           

my $x=$im_x->Composite(compose=>'Plus', image=>'image.png', mask=>'mask.png');
warn "$x" if "$x";

$im_x->Write("image_mask2.png");

undef $im_x;

Code: Select all

#!/usr/bin/perl -w
use strict;
use Image::Magick;

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

my $mask =Image::Magick->new;
$mask->Read("mask.png");

my $im_x;
$im_x=Image::Magick->new;

my $x=$im_x->Composite(compose=>'Plus', image=>$image, mask=>$mask);
warn "$x" if "$x";

$im_x->Write("image_mask3.png");
$image->Write("image3.png");
$mask->Write("mask3.png");

undef $im_x;
undef $image;
undef $mask;
The script always ended with a message
Exception 410: no images defined `Composite' @ error/Magick.xs/XS_Image__Magick_Mogrify/7336 at ./compose_test1.pl line 9 (or 15).
and image_mask.png files are not created.

I use perl-PerlMagick 6.6.5.8-7.3, ImageMagick 6.6.5.8-7.3, Perl 5.12.3-11.14.1 on openSUSE 11.4.

What am I doing wrong?

Re: problem running composite - exception 410

Posted: 2011-06-26T18:41:39-07:00
by anthony
You need to read (or at least create) BOTH images into separate image arrays first!
That is what that error is telling you. One or both images are not present!

Code: Select all

#!/usr/bin/perl
use Image::Magick;
$dest = Image::Magick->new();
$dest->Read('granite:');

$src = Image::Magick->new();
$src->Read('rose:');

$offset="+10+10";

$dest->Composite(image=>$src, compose=>'over', geometry=>$offset);

$dest->write("show:");
Composite() does not create a new image. It only overwrites an existing image. If you want to preserve the original image, clone it first!

See Examples in PerlMagick/demo subdirectory of the sources. (probably loaded in "/usr/share/docs/ImageMagick-perl-*/demo" on your linux machine).

Re: problem running composite - exception 410 [solved]

Posted: 2011-06-27T09:49:48-07:00
by symulant
Anthony, thank you for your reply.