Gossamer Forum
Home : General : Perl Programming :

Printing an image

Quote Reply
Printing an image
Does anyone know how to print an in perl, not using the <img src=""> tag but incorporating the image into the perl script.

Matt
Quote Reply
Re: Printing an image In reply to
Hi,

This should work:

Code:
print "Content-type: image/gif\n\n";
open (IMG, "/path/to/image.gif") or die $!;
while (<IMG> ) { print; }
close IMG;

Cheers,

Alex
Quote Reply
Re: Printing an image In reply to
Well, the script grabbed the image and displayed its size in the title bar but the only thing that showed up in the browser was a broken image graphic.

Matt
Quote Reply
Re: Printing an image In reply to
You might also try adding:

binmode(IMG);

just after the open() call if you are on a windows operating system, or one that cares about binary/ascii files.

Cheers,

Alex
Quote Reply
Re: Printing an image In reply to
This should help you:

Code:

print "Location: http://yourserver.com/yourimage.gif\n\n"


Regards,

Pasha

------------------
webmaster@find.virtualave.net
http://find.virtualave.net
Quote Reply
Re: Printing an image In reply to
Hi.

First check that you are trying to print out the appropriate file type...meaning if you are using this script on a jpg you need to change this:
"Content-type: image/gif\n\n"
To:
"Content-type: image/jpg\n\n"

Otherwise you might want to try changing this line:
while (<IMG> ) { print;}
to
while (<IMG> ) { print $_;}

I think this might work...

What Pasha is suggesting will not work because you've already print a Content-type header. Though his idea will work if you take out the "Content-type: image/gif\n\n"
It doesn't read in your image first before displaying it!

Hope this helps Smile
Rod
Quote Reply
Re: Printing an image In reply to
I dont know what the problem is. I tryed everything that you guys suggested and I still have the same problem. My code is :
Code:
#!c:/perl/perl.exe

print "Content-type: image/gif\n\n";
open (IMG, "../public_html/images/city.gif") or die $!;
binmode(IMG);
while (<IMG> ) { print $_;}
close IMG;

exit;
The url is http://www.outbreak.dhs.org/images/image.pl
Does anyone have any ideas?

Matt