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!

Help with Image::Magick

Status
Not open for further replies.

BenRussell

Programmer
Mar 12, 2001
243
US
I am trying to read a file (that I know exists and is readable, called 'EXISTING_IMAGE.jpg') and then simply print it back out to the browser via a Perl script. I am using the following code:

Code:
print "Content-type: image/gif\n\n";

# Read the image
$image->Read("EXISTING_IMAGE.jpg");

# Resize the image
$image->Resize(
	width => '200',
	height => '100'
);

# Save the image
my $return = $image->Write('gif:-');

However, it returns a broken image, and $return returns nothing.

- Ben
 
Oh yeah, also, $image is a refernce to an object to the Image::Magick->new method.

I also tried changing the content-type to image/jpg and writing it as a jpg, and it still would not work.

- Ben
 
Actually, originally what I was trying to do was create a script that would make an image (200 x 100 pixels) that contained 6 random letters/numbers.

I would use this image to prevent automated form registrations. However, I could not even get an image to print out, so I had to try other things. If anyone could help me on just figuring out my original problem (creating the image with the random 6 letters/numbers), then that would be great.

Thanks.

- Ben
 
You might want to try the discussion boards here for anything specific to Image Magick:


This kind of worked for me - For some reason the text comes out underneath the original image and I can just see the top of the characters if I make the point size really large.
Code:
use Image::Magick;
$image = Image::Magick->new;
$text = 'text';
$image->Read('bg.jpg');
$image->Annotate(font=>'c:/winnt/fonts/arial.ttf',pointsize=>20, fill=>'black', text=>$text);
$image->Write('output.gif');
 
How would I print it to STDOUT instead of a file called 'output.gif'?

- Ben
 
First off, you'd need to make sure you're outputting a valid Content-Type header I'd think.

--Paul
 
So once I put the appropriate Content-type header, then what would i do?

- Ben
 
Whatever the imagedata should be, as far as I know its just a datastream

--Paul
 
Yes, but in Perl-language how would i do this?

- Ben
 
try
$image->Write();
or
$image->Write(STDOUT);

--Paul
 
I have been attempting to learn to use perl magick as well, and have been following this thread, hoping for an answer. but check this out, from the imagemagick.org website:

Use - as the filename to method Read() to read from standard in or to method Write() to write to standard out:
Code:
    binmode STDOUT;
    $image->Write('png:-');

check that page out, its got some info on it.

Robert Carpenter
--------------------
"Isn't it funny how you are perfectly content with being alone until nobody else is?"
--------------------
linkemapx@hotmail.com
toyboxhosting.net
 
To write an image, use this:

$image->Write(filename=>"YOUR_FILENAME");

YOUR_FILENAME == test.gif, test.png, or something like that.

You can also give other options in the write command, like what compression to use and what not.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top