简体   繁体   English

Javascript Hex String to Image

[英]Javascript Hex String to Image

I'll cut right to the chase. 我会切入正确的追逐。 Right now I am developing a web based application. 现在我正在开发一个基于Web的应用程序。 It has a PHP REST based architecture that serves up XML documents. 它有一个基于PHP REST的架构,可以提供XML文档。 On many of these documents attributes are hex encoded picture strings. 在许多这些文档中,属性是十六进制编码的图片串。

On the client side jQuery AJAX fetches an XML document with a picture in it. 在客户端,jQuery AJAX获取带有图片的XML文档。 I need to display said picture in some <img> tags. 我需要在一些<img>标签中显示所述图片。 However my knowledge on such methods is lacking so here I am asking for help. 但是我对这些方法的了解不足,所以我在这里寻求帮助。

Goal: JavaScript String variable in hex or base64 >>> HTML displayed image. 目标:十六进制或base64中的JavaScript字符串变量>>> HTML显示的图像。

Cross browser is required, or a hack for the ones that do not support it is fine. 需要跨浏览器,或者对不支持它的黑客很好。

Thanks, Gunnar 谢谢,Gunnar

Encode the images using base64 and write them out in a CDATA string into your XML with this format: 使用base64对图像进行编码,并使用以下格式将它们以CDATA字符串形式写入XML:

data:[<MIME-type>][;charset="<encoding>"][;base64],0123456789abcdefg...

When constructing your document, use this string as your src 构建文档时,请使用此字符串作为src

<img src="data:image/png;base64,0123456789abcdefg..." />

Is it possible to use a php file just for rendering the image? 是否可以使用php文件来渲染图像? That php file could write some base64 encoded values via 该php文件可以通过写入一些base64编码的值

echo base64_decode($_GET['data']); 

while you embed images like 当你嵌入图像时

<img src="http://host/yourPhpFileForDecode.php?data=base64encoded.../>

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

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