Page 1 of 1

"Hello World" with ImageMagick

Posted: 2008-08-14T15:12:33-07:00
by ReeDees
Hi all,

I've read through much of perlmagick documentation and am quite impressed; I can't wait to use it. However, i'm having trouble duplicating typical "convert" functionality. For example, for a typical "convert -size 100x100 xc:white foobar.png" I wrote some simple perl:

Code: Select all

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

use Image::Magick;

my $filename = "foo.png";

eval
{ 
  my $image = Image::Magick->new(size => '100x100');
  $image->ReadImage('xc:white') || die $!;
  $image->Write(filename => $filename) || die $!;
  open(IMAGE, ">$filename");
  $image->Write(file=>\*IMAGE, filename=>$filename) || die $!;
  close(IMAGE);
};
print $@ if $@;
I see an error, which i'm sure is something *incredibly* simple that I overlooked, "No such file or directory at ./image.pl line 11." which is my ReadImage line. What simple thing am I overlooking?

Re: "Hello World" with ImageMagick

Posted: 2008-08-14T16:47:34-07:00
by magick
> $image->ReadImage('xc:white') || die $!;

For proper exception handling, see http://www.imagemagick.org/script/perl- ... exceptions.

Re: "Hello World" with ImageMagick

Posted: 2008-08-14T17:03:18-07:00
by ReeDees
Thanks! Got it working now!