当前位置:  开发笔记 > 编程语言 > 正文

jpeg的有效base64字符串

如何解决《jpeg的有效base64字符串》经验,为你挑选了1个好方法。

这是jpeg的有效base64字符串吗?

data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/2wBDAQMDAwQDBAgEBAgQCwkLEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBD

所讨论的字符是“ base64”之后的“ / 9j /”,

我猜这可能与压缩有关,因为它是JPEG。

正如与png的base64字符串相比时,模式是不同的,即字符模式与上面的不同。

 data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAe8AAADICAYAAADBV2n3AAAIc0lEQVR4Xu3VgQkAAAgCwdx/6eZ4uCaQM3DnCBAgQIAAgZTAUmmFJUCAAAECBM54ewICBAgQIBATMN6xwsQlQIAAAQLG2w8QIECAAIGYgPGOFSYuAQIECBAw3n6AAAECBAjEBIx3rDBxCRAgQICA8fYDBAgQIEAgJmC8Y4WJS4AAAQIEjLcfIECAAAECMQHjHStMXAIECBAgYLz9AAECBAgQiAkY71hh4hIgQIAAAePtBwgQIECAQEzAeMcKE5cAAQIECBhvP0CAAAECBGICxjtWmLgECBAgQMB4+wECBAgQIBATMN6xwsQlQIAAAQLG2w8QIECAAIGYgPGOFSYuAQIECBAw3n6AAAECBAjEBIx3rDBxCRAgQICA8fYDBAgQIEAgJmC8Y4WJS4AAAQIEjLcfIECAAAECMQHjHStMXAIECBAgYLz9AAECBAgQiAkY71hh4hIgQIAAAePtBwgQIECAQEzAeMcKE5cAAQIECBhvP0CAAAECBGICxjtWmLgECBAgQMB4+wECBAgQIBATMN6xwsQlQIAAAQLG2w8QIECAAIGYgPGOFSYuAQIECBAw3n6AAAECBAjEBIx3rDBxCRAgQICA8fYDBAgQIEAgJmC8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AIGYgPGOFSYuAQIECBAw3n6AAAECBAjEBIx3rDBxCRAgQIDAA8MHAMnDFd9nAAAAAElFTkSuQmCC

我的问题的根源是我将base64画布数组编码为.jpeg和.png--.png的输出很好,而.jpeg的总是输出为黑盒。

我正在使用html2canvas(javascript)捕获图像,它们是html节点的“图像”,我一直在解决透明度问题,例如将dom节点的背景设置为白色。

我正在编码的所有jpeg图像都具有这种“ / 9j /”模式,我在循环中生成它们,因此它很可能是所有图像都具有的共同属性。

我似乎也找不到网上一种不错的工具来验证base64字符串。



1> robertklep..:

让我们检查:

$ echo -n '/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgID' | base64 --decode | file -
/dev/stdin: JPEG image data, JFIF standard 1.01

因此,它被认为是有效的JPEG标头(​​不过,这不一定意味着整个JPEG数据都是有效的,但至少看起来像是JPEG)。

JPEG数据和PNG数据之间的差异是因为文件格式不同。此外,/在Base64中也是有效字符。

推荐阅读
路人甲
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有