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

Re: Serving images with perl

by cbrandtbuffalo (Deacon)
on Oct 14, 2005 at 15:13 UTC ( [id://500252]=note: print w/replies, xml ) Need Help??


in reply to Serving images with perl

If you are going to read in the files and serve them through the perl script, you may want to check out this article on slurping in files quickly.

Replies are listed 'Best First'.
Re^2: Serving images with perl
by fluffyvoidwarrior (Monk) on Oct 15, 2005 at 08:34 UTC
    Thanks.
      I worked it out in the end. Its head slappingly simple Thanks everyone Heres the finished script:-
      #!/usr/bin/perl -w =comment This is for customer proofs NOT cam/management proofs Responds to a request for a customer proof image from the internet +. Reads the requested image from disk and serves it back to the brow +ser. Used to serve private images that are not on the apache tree in re +sponse to a browser request to fill an image tag eg <img src=\"http://www.caralan.com/cgi-bin/customer_image_server.cg +i?load_image=cust__stevecaralancom1129266425_00.gif\" border=\"0\" a +lt=\"\"> =cut use strict; use CGI; #use File::Copy; #use Tie::File; #use Fcntl qw( :DEFAULT :flock ); use steves_general_functions; my $mycgi = new CGI; my $imagedata = ""; my $load_image = $mycgi->param( "load_image" ); $load_image = &gen_wash_input($load_image, "filename"); my $proof_folder = "/caralan_com/system/proofing/customer_proofs/proof +s_out/"; my $imagefile = $proof_folder . $load_image; #Set mime type for returned binary dump if( lc(&gen_get_extension_from_path($imagefile)) eq ".gif"){ print "Content-type: image/gif\n\n"; } if( lc(&gen_get_extension_from_path($imagefile)) eq ".jpg"){ print "Content-type: image/jpeg\n\n"; } if( lc(&gen_get_extension_from_path($imagefile)) eq ".tif"){ print "Content-type: image/tif\n\n"; } #Slurp binary image data from diskfile { local( $/, *IMAGEFILE ) ; open( IMAGEFILE, $imagefile ); $imagedata = <IMAGEFILE>; close IMAGEFILE; } #Send binary dump to browser print $imagedata;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-26 00:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found