Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: CGI and image

by bart (Canon)
on Dec 18, 2016 at 11:19 UTC ( [id://1178004]=note: print w/replies, xml ) Need Help??


in reply to CGI and image

Traditionally, I would have answered in the same way as NetWallah did in his reply. That is: send the HTML file with a link to the image, for which you don't even need to use CGI. That's how we've done it for almost 20 years already.

But in the modern world, there is another option, and that is much closer to your own solution, and that is to embed the PNG file into your HTML. For that, you have to base-64 encode your image file data, slap a content-type in a form of header on it and put that as the source of the <img> tag, using the data: protocol. The code could look like this:

use MIME::Base64; printf '<img src="data:image/png;base64,%s">', encode_base64($image);
where the rest of you code can remain the same.

I would not recommend this for huge files, as it increases the transfer byte size by 33%, but for tiny images of a few k at most that is definitely a good alternative, since it limits the number of server requests.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 21:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found