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