Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open an image using Image::Magick

Status
Not open for further replies.

dalhousi

Programmer
Mar 26, 2007
21
CA
Hi everyone,

I've been trying to use the library Image::Magick to open an image, write some text in it, and then print it.

However, all I could do is to write some text on a white (or any other color) background. I want to set an image of mine as the background of the picture.

I tried the subroutine ReadImage('MY_PICTURE_PATH') but it didn't work.

Here is the source code I wrote:

Code:
sub print_button{
	my $class = shift;
	my $text = shift;
	
	my $width  = 200;
	my $height = 200;
	my $size = $width."x".$height;
	
	my $image   = Image::Magick->new();
	$image->Set(size=>$size);
	
	$image->ReadImage('xc:white');
	$image->Set(magick => 'gif');
	$image->Annotate(
           text      => $text,
           fill      => 'black', #$color,
           pointsize => 20,
           gravity   => 'Center',
           font      => $char_font,
           antialias => 'true'
        );	  
        my @blobs = $image->ImageToBlob();
        print $blobs[0];
 }

Any suggestions or comments will be highly appreciated.
Thanks in advance,
Cheers,
 
Hi guys,

It was my mistake. When I tried to read a picture, I have used the absolute path:
$image->ReadImage('/images/MY_PICTURE');

However, I should have used:
$image->ReadImage('../../images/MY_PICTURE');


Thanks,
Cheers,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top