开发者

How do I encode an image?

开发者 https://www.devze.com 2023-03-06 23:24 出处:网络
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开发者_运维问答

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消