Superlman has asked for the wisdom of the Perl Monks concerning the following question:
(Blah blah HTML) <IMG SRC = "http://www.server.com/cgi-bin/image.pl?iwant=5 (blah blah HTML)
And this would then produce whatever image the server things should be produced for the number "5". My current method of doing things is as follows:
#!/usr/bin/perl use POSIX; my $path = "/path/to/images"; my $imagereq = param('iwant'); #If you don't give an image, it assumes you #want image 0, the defaut image. unless($imagereq) { $imagereq = 0; } #If the image you requested exists (all are JPEG), then #we set our path to reflect this if(-e "$path/$imagereq".".jpg") { $path = "$path/$imagereq".".jpg"; } #Otherwise, we give them an special image else { $path = "$path"."404.jpg"; } #Open the image and 'print' it, which the browser #is quite happy to accept and display as an image open IMAGE, "$path" or die "ACK! $!"; print "Content-type: image/jpeg\n\n"; binmode STDOUT; while(<IMAGE>) { print STDOUT $_; }
Now, this works just fine. However, I would greatly appreciate any suggestions others may have, either in improving the current code or suggesting a whole other approach.
Some points:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: 'Printing' an Image to a Browser
by Aristotle (Chancellor) on Aug 11, 2002 at 04:22 UTC | |
|
•Re: 'Printing' an Image to a Browser
by merlyn (Sage) on Aug 11, 2002 at 10:48 UTC |