开发者

HTML: How can I display an image using just its hex representation [duplicate]

开发者 https://www.devze.com 2023-03-06 11:51 出处:网络
This question already has answers here: Is it possible to put binary image data into html markup and then get the image displayed as usual in any browser?
This question already has answers here: Is it possible to put binary image data into html markup and then get the image displayed as usual in any browser? (6 answers) 开发者_如何学编程 Closed 2 years ago.

Possible Duplicate:

Is it possible to put binary image data into html markup and then get the image displayed as usual in any browser?

So for example I have an image like:

\x89PNG\r\n\u001A\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0001@\u0000\........

Is there any way that from that I can show the image in a img tag?


You can't show it natively without assistance to convert it.

If you base 64 encode it instead, you can.

<img src="data:image/png;base64,iVBrkJggg==" alt="Base 64 encoded!" />

Further Reading.


You can't do that with HTML only. The img tag can only display images via the URL supplied in the src attribute. You could set src to the URL of a page on your server that prints the hex string. For example:

<img src="myimage.php" />

myimage.php:

header("Content-type: image/png")
print $hex_string
0

精彩评论

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