Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by knowmad (Monk)
on Oct 13, 2005 at 22:43 UTC ( #500070=categorized answer: print w/replies, xml ) Need Help??

Q&A > CGI programming > How can I use a CGI script to return an image? - Answer contributed by knowmad

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
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2020-07-02 09:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?