简体   繁体   English

在firefox上将图像转换为base64 javascript

[英]Convert image to base64 javascript on firefox

I need to convert image that are in a webpage to base64 over greasemonkey or firefox .xpi extension. 我需要通过滑脂或firefox .xpi扩展名将网页中的图像转换为base64。 How can i do it? 我该怎么做? I know that i have btoa() function, but i only can use it with strings, not with images. 我知道我具有btoa()函数,但是我只能将其与字符串一起使用,而不能与图像一起使用。 Little help here. 这里没有什么帮助。 Thanks. 谢谢。

You could use the canvas element and draw the image using drawImage() onto it, then use toDataURL() to get the base64 encoded image. 您可以使用canvas元素,并使用drawImage()在其上绘制图像,然后使用toDataURL()获得base64编码的图像。

see: https://developer.mozilla.org/en/html/canvas 参见: https : //developer.mozilla.org/en/html/canvas

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

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