How do I encode an image?
I was reading this blog http://alexrogan.com the writer talks about adding an encoded image to a web page. His explanation was easy enough to understand, however he did not explain how开发者_运维问答 to encode the image in the first place.
So, I would like to know how do I encoding an image?
Thanks
Here's a php sample:
<?php
$data = file_get_contents('somepic.jpg');
$base64 = base64_encode($data);
?>
<img src="data:image/jpeg;base64,<?php echo $base64 ?>" />
base64 is base64, no matter what OS you're on.
You need a base64 encoder for that. Try for example http://www.motobit.com/util/base64-decoder-encoder.asp. Upload your image to the site and a base64 representation will be generated for you to cut-and-paste into your HTML.
精彩评论