开发者

How can I get the base64 string of an image using JS

开发者 https://www.devze.com 2023-02-14 02:32 出处:网络
I\'m trying to get the base64 string of an image using only javascript. This has 开发者_如何学编程to work only on firefox 3.5+ since it\'s a greasemonkey script.

I'm trying to get the base64 string of an image using only javascript.

This has 开发者_如何学编程to work only on firefox 3.5+ since it's a greasemonkey script.

I can't use the canvas workaround since it's on a another server and this throws a security exception.

Thanks for any idea.


Maybe there's a more elegant solution but you can create a canvas with the dimensions of your image, use drawImage to put your image on the canvas, use toDataURL with the MIME type that you want and get a data: URL which will be something like "data:image/png;base64," and then the base64 representation of the image in a given format.

Oh, I've just read that it's on another server. Then you can't have the base64. Sorry. The only information you can get are the dimensions.


base64.js is what you are looking for

0

精彩评论

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