Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How can I use a CGI script to return an image?

by cianoz (Friar)
on Sep 07, 2000 at 15:19 UTC ( [id://31379]=note: print w/replies, xml ) Need Help??


in reply to How can I use a CGI script to return an image?

Supposing your image is in a file, and you want your script to stream its contents on-demand:
open IMAGE, "/path/to/image.jpg"; #assume is a jpeg... my ($image, $buff); while(read IMAGE, $buff, 1024) { $image .= $buff; } close IMAGE; print "Content-type: image/jpeg\n\n"; print $image;
or, faster and easier:
use File::Copy; print "Content-type: image/jpeg\n\n"; copy "/path/to/image.jpeg", \*STDOUT;

Replies are listed 'Best First'.
RE: Answer: How can I use a CGI script to return an image?
by merlyn (Sage) on Sep 07, 2000 at 16:51 UTC
    Or simpler (because I hate typing):
    use File::Copy; print "Content-type: image/jpeg\n\n"; copy "/path/to/image.jpeg", \*STDOUT;
    And then you don't even have to type binmode STDOUT as another monk in this thread suggested, because copy does it for you.

    -- Randal L. Schwartz, Perl hacker

RE: Answer: How can I use a CGI script to return an image?
by Jouke (Curate) on Sep 07, 2000 at 15:29 UTC
    don't forget
    binmode STDOUT;
    before you print the image to standard out... Jouke Visser, Perl 'Adept'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://31379]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found