Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by knowmad (Monk)
on Oct 13, 2005 at 22:43 UTC ( [id://500070]=note: print w/replies, xml ) Need Help??


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

In case the OP was actually wanting to use the script to return an image, not html, here's another way to do it. This script uses LWP to grab an image from another server and send it along. You can use it inside the src attribute of an image tag.

use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $response = $ua->get('http://www.perl.org/simages/lcamel.gif'); die "Unable to retrieve image." unless ($response->is_success); print "Content-type: image/jpeg\n\n"; print $response->content;
William

Replies are listed 'Best First'.
Re: Answer: How can I use a CGI script to return an image?
by Trimbach (Curate) on Oct 14, 2005 at 13:17 UTC
    Sure... but why are you pulling down a gif and sending out a jpeg? The Content-type of the file you fetch and the file you send on should match.

    Gary Blackburn
    Trained Killer

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-19 18:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found