Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Display image file in browser

by ITmajor (Beadle)
on Jul 15, 2008 at 20:22 UTC ( #697797=perlquestion: print w/ replies, xml ) Need Help??
ITmajor has asked for the wisdom of the Perl Monks concerning the following question:

What function do you use in Perl to display an image file in a browser? If I want to display both text and an image, should I use two separate headers or create another program?



Apparently there is some confusion as to what I'm trying to do. Here's more clarification:
I want to output 2 images from my perl script to the browser, one will be generated within the script and the other is a separate image file stored on the server. I want to output both images as well as some text.

When I tried to open the file with this:
$q->header("image/png\n\n")
open(FILE, "name_of_image";
while (<FILE>);
print "$_\n";

I get a bunch of symbols and gibberish. I thought that maybe there is another function to display image files vs. text files. Also, since I want to output both text & images, I wanted to know if I can use 2 different header types in my script or should I create a separate script for text & another for images.

Comment on Display image file in browser
Re: Display image file in browser
by friedo (Prior) on Jul 15, 2008 at 20:35 UTC

    You don't use a function in Perl to display an image file in a browser. If you want to display an image in a browser, you use HTML.

    If the image in question must be dynamically generated by a CGI program, then point the src attribute from the img tag at the right program, and have that program output the correct content-type header so the browser knows it's getting an image.

Re: Display image file in browser
by Joost (Canon) on Jul 15, 2008 at 20:38 UTC
Re: Display image file in browser
by alexm (Chaplain) on Jul 15, 2008 at 21:42 UTC
      this is not the same question, I am trying to bring up a different file (that is completely unrelated) as a comparison
        I am trying to bring up a different file (...) as a comparison

        Unless you provide further details, it does seem the same question to me, sorry. Maybe if you could show us some code, it will be easier to understand the difference.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://697797]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (13)
As of 2014-08-29 14:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (280 votes), past polls