Page 1 of 1

Syntax-Documentation Inconsistency?

Posted: 2008-09-25T20:46:44-07:00
by SidShakal
On the PerlMagick documentation page the following example code is given, intended to draw three red rectangles in a drawing area:

Code: Select all

   $image->Draw(fill=>'red', primitive=>'rectangle',
     points=>'20,20 100,100  40,40 200,200  60,60 300,300');
I've tried this (and several variations on this), and it seems to silently fail as if the value for 'points' is invalid.

I'm wondering then, is it the page that's wrong, or is it something on my end?

Also, here's the source to a perl script to try it yourself:

Code: Select all

#!/usr/bin/perl
use strict;
use warnings;

use Image::Magick;

my $image = Image::Magick->new;
$image->Set('size'=>'320x320');
$image->ReadImage('xc:white');

$image->Draw('fill'=>'red', 'primitive'=>'rectangle',
        'points'=>'20,20 100,100  40,40 200,200  60,60 300,300');

# To achieve what was intended by the previous line, uncomment
#   the following three:
#$image->Draw('fill'=>'red', 'primitive'=>'rectangle', 'points'=>'20,20 100,100');
#$image->Draw('fill'=>'red', 'primitive'=>'rectangle', 'points'=>'40,40 200,200');
#$image->Draw('fill'=>'red', 'primitive'=>'rectangle', 'points'=>'60,60 300,300');

# The following line may be used to display the image on the screen,
#   at least under X11
#$image->Display($ENV{'DISPLAY'});

$image->Write('output.png');
I'd appreciate any insight,
-- Sid

Re: Syntax-Documentation Inconsistency?

Posted: 2008-09-25T20:52:49-07:00
by magick
Grab the ImageMagick source distribution and take a look at ImageMagick-6.4.3/PerlMagick/demo/shapes.pl. It has a working example of drawing with PerlMagick.

To determine why Draw() is failing, check for exceptions:
  • $x = $image->Draw(...);
    echo $x if "$x";