开发者

base32 image for img tag

开发者 https://www.devze.com 2023-03-17 00:41 出处:网络
I have faced an interesting thing as... if I use this code to download image as a string for Base64 encoded byte array it works fine

I have faced an interesting thing as... if I use this code to download image as a string for Base64 encoded byte array it works fine

data:image/png;base64,<String>

But I was tring to encode the same image to Base32 and call it as

data:image/png;base32,&开发者_运维技巧lt;String>

But that way doesn't work. Maybe I am using some wrong protocol or something... :(

So my question is... How to call Base32 image for img tag?

Thanks


If you mean the browser isn't displaying the image, all it means is that the browser doesn't support base32. I have the same issue with Iceweasel4, Firefox 3, and Chrome 12. IE7 doesn't show either base64 or base32-encoded inline images.

Here are the files I'm using for test, stolen from http://www.sweeting.org/mark/blog/2005/07/12/base64-encoded-images-embedded-in-html:

test1.html shows fine in Firefox, Iceweasel, Chrome:

<img src="data:image/gif;base64,R0lGODlhUAAPAKIAAAsLav///88PD9WqsYmApmZmZtZf
YmdakyH5BAQUAP8ALAAAAABQAA8AAAPbWLrc/jDKSVe4OOvNu/9gqARDSRBHegyGMahqO4R0bQcj
IQ8E4BMCQc930JluyGRmdAAcdiigMLVrApTYWy5FKM1IQe+Mp+L4rphz+qIOBAUYeCY4p2tGrJZe
H9y79mZsawFoaIRxF3JyiYxuHiMGb5KTkpFvZj4ZbYeCiXaOiKBwnxh4fnt9e3ktgZyHhrChinON
s3cFAShFF2JhvCZlG5uchYNun5eedRxMAF15XEFRXgZWWdciuM8GCmdSQ84lLQfY5R14wDB5Lyon
4ubwS7jx9NcV9/j5+g4JADs=">

test2.html doesn't show in any browser I have.

<img src="data:image/gif;base32,I5EUMOBZMFIAADYAUIAAACYLNL77776PB4H5LKVRRGAK
MZTGM3LF6YTHLKJSD6IEAQKAB7YAFQAAAAAAKAAA6AAAAPNVROW47YYMUSKXXA4OXTN375QKQBCD
JEIEO6QMQYY2Q2R3QR2G2BZDEEHQJYATAJA4656QTFXMQZDGOQABY5RIUAYLK2YCSTMFWLSFFDGU
QQPPRST6F6FOTBZ7VIQOAQCRQ6BGHCTWWRVMSZPB7XF36ZTGY2YBNBUII4IXOJZITDDODYRQM34S
SOJJC33GHYMW3B4CRF3I5CFAOCPRQ6D6PN6XW6JNQGOIPBVQUGFHHDNTO4CQCKCFC5RGDPBGMUNZ
XHEFQNXJ7F46OUOEYAC5PFOECUK6AZLFTVZCXDHQMCTHKJB44JJNA7MOKHLYYAYHSLZKE7RON4CL
XDY7JVYV674PT6QOBEADW===">

I used b64decode and b32encode from Python's base64 module to create the base32-encoded image from the base64-encoded image.

According to https://www.rfc-editor.org/rfc/rfc2397, the formats supported are base64 and plain ASCII (for those characters outside the range of printable 7-bit characters, you use the standard %XX hex-encoding.)

IE apparently doesn't support any in-line images until IE8.

0

精彩评论

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

关注公众号