Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by xjar (Pilgrim)
on Sep 07, 2000 at 01:03 UTC ( #31327=note: print w/replies, xml ) Need Help??


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

If lhoward's answer isn't what you were looking for exactly (i am only assuming this because you said you were a perl newbie and you probably wouldn't have any GD knowledge if you were :) then this might be what you're looking for. Rather than using an

<img src="...">

tag, you could use an href to go to the perl script which will then display the specified image file like this

<a href="/cgi-bin/image.cgi?image=image.jpg">

In this way, you can have one script display all your images based on the filename in the URL, and each image will be displayed on a page with the same "Look and Feel" without having to write multiple pages.

#!/usr/bin/perl use strict; use CGI; my $cgi = new CGI; my $image = $cgi->param('image'); print "Content-type: text/html\n\n"; print "<html><head><title>$image</title></head>\n"; print "<body>\n"; print "<center>\n"; print "<img src=/images/$image><p>\n"; #The path here would obviously +be different according to where your images are at print "</center>\n"; print "</body>\n"; print "</html>\n";

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2021-09-24 20:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?