I need to convert image that are in a webpage to base64 over greasemonkey or firefox .xpi extension. How can i do it? I know that i have btoa() function, but i only can use it with strings, not with images. Little help here. Thanks.
1 Answer
You could use the canvas element and draw the image using drawImage() onto it, then use toDataURL() to get the base64 encoded image.
4 Comments
Buterrip
In order to use canvas element this would not be fine, because i'm doing a script to interact with another page. There's not another way? Or can i use that functions without calling canvas element?
stewe
Maybe there is another way, but for those functions mentioned, you need a
canvas elementButerrip
Ok, could you please give me a example?
stewe
Found a good example here: stackoverflow.com/questions/934012/get-image-data-in-javascript/…