简体   繁体   English

如何编码图像?

[英]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. 我正在阅读此博客http://alexrogan.com ,作者谈到将编码的图像添加到网页中。 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示例:

<?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. 无论您使用什么操作系统,base64都是base64。

You need a base64 encoder for that. 为此,您需要一个base64编码器。 Try for example http://www.motobit.com/util/base64-decoder-encoder.asp . 尝试例如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. 将您的图片上传到网站,然后将生成base64表示形式,供您剪切并粘贴到HTML中。

看看这个... Base64编码图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM