Page 1 of 1

[Solved] Composite fail: 410: reference is not my type `Imag

Posted: 2014-06-12T07:50:20-07:00
by tampadavid
I've looked and head banged this extensively, so now I'm asking for help. Seems that I cannot predict, thus cannot rely on, which parts of the documentation are going to work as advertised. So far, for me and my efforts, Label does not work, and now Composite does not work. This post relates to Composite.

Here's the test script:

Code: Select all

#!/usr/bin/env perl

# perl-jsiiw-Composite.pl: trying to get im's Composite method to work.

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


my ($doll, $t, $coal, $w);

# These are 300x300px pngs from gimp.  the black-dot is transparent, except 
# for the dot.  Ideally, this puts the dot on the white destination png.
$doll = "./white-box-300x300.png";
$t = "./black-dot-300x300.png";

$coal = Image::Magick->new;

$w = $coal->Read("$doll");
warn $w if $w;
$w = $coal->Composite(image=>"$t", compose=>'over', geometry=>"+4+4", gravity=>'center');  # Line 20.
warn $w if $w;
$w = $coal->Write("./blackdot.png");
warn $w if $w;
And here is the error I get when it is run:
Exception 410: reference is not my type `Image::Magick' @ error/Magick.xs/XS_Image__Magick_Mogrify/7505 at /home/david/bin/perl-jsiiw-Composite.pl line 20.
Even when I reduce the method to just reading the image, it fails with that message. Funny though, if I feed it a () it gives:
Exception 410: composite image required `Image::Magick' @ error/Magick.xs/XS_Image__Magick_Mogrify/8279 at /home/david/bin/perl-jsiiw-Composite.pl line 23.
so at least this indicates that the $coal->Composite() method does exist, or else it would not be there to complain. (?)

The test files are a 300x300 white box, and a 300x300 transparent box with a black spot in the middle. I am trying to put the spot on the white background. What I get instead is this error message. This is not the only time Composite has failed. I have been trying to incorporate it into a production script, but cannot, because it does not work at all, according to my attempts based on available documentation.

I've looked for good books on ImageMagick, and there are not any "good" books. I think this is because even those who attempt to write such a book find the project itself too un-documented, or worse, incorrectly documented, to research and report useful reliable information. The point I am making, at least to myself, is that I am not alone in this frustration. That and that I have really tried to find out why Composite is failing.

Your help is needed and appreciated.


David

Re: Composite fail: 410: reference is not my type `Image::Ma

Posted: 2014-06-12T08:01:31-07:00
by snibgo
The documentation http://www.imagemagick.org/script/perl-magick.php says: image=>image-handle. See also examples on this forum, eg viewtopic.php?f=7&t=22255&p=92146.

Re: Composite fail: 410: reference is not my type `Image::Ma

Posted: 2014-06-12T08:46:02-07:00
by tampadavid
That's just it. I do not think there is anything wrong with the statement:

Code: Select all

$w = $coal->Composite(image=>"$t", compose=>'over', geometry=>"+4+4", gravity=>'center');
or

Code: Select all

$w = $coal->Composite(image=>$t, compose=>'over', geometry=>"+4+4", gravity=>'center');
and I did not include the documentation in the post, only mentioned it.

I believe something is broken, but I do not know enough to really say. Also, I'd expect more traffic here if something were broken. Or this product is not used nearly as often as I thought.

It still fails. Can anyone see anything wrong with this statement(s)? Can anyone point me to working examples? I have not found any that differ from what I've done here.


David

Re: Composite fail: 410: reference is not my type `Image::Ma

Posted: 2014-06-12T09:33:03-07:00
by snibgo
Correct me if I'm wrong, because I don't do perl, but your $t is a string, "./black-dot-300x300.png".

But "image=>" needs an image handle, not a string. This image handle needs to have been "read" before you use it in Composite. See the example in the thread I linked.

Re: Composite fail: 410: reference is not my type `Image::Ma

Posted: 2014-06-12T19:36:20-07:00
by tampadavid
Whow! RTFP.

You are correct, sir. I now realize that there is no particular "ImageMagick", there is instead, a confederation of programs that combine to form this distribution of graphics utilities called "ImageMagick". I say that because building gif animations takes filenames, not image handles. Hats off and thank you. I would not have gotten this without your help.

Here's the working example:

Code: Select all

#!/usr/bin/env perl

# perl-jsiiw-Composite.pl: trying to get im's Composite method to work.

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


my ($doll, $t, $coal, $sharona, $w);

# These are 300x300px pngs from gimp.  the black-dot is transparent, except 
# for the dot.  Ideally, this puts the dot on the white destination png.
$doll = "./white-box-300x300.png";
$t = "./black-dot-300x300.png";

$sharona = Image::Magick->new;
$w = $sharona->Read($t);
warn $w if $w;
$coal = Image::Magick->new;
$w = $coal->Read("$doll");
warn $w if $w;
#$w = $coal->Composite(image=>$t);
$w = $coal->Composite(image=>$sharona, compose=>'over', geometry=>"+4+4", gravity=>'center');
warn $w if $w;
$w = $coal->Write("./blackdot.png");
warn $w if $w;
With the particular lesson being the need to record the overlay image in an image object, rather than being read from a file. Also, trying to extrapolate from examples using the bash versions does not indicate this step.

Thank you again snibgo. Marking [solved]


David