I am loading an image in React from a URL external to my app:
<img id={selectedImage.id} src={selectedImage.url} \>
Now I want the user to be able to press a button and the app should store the image content as base64 data in some variable.
Is there any way for me to reference this specific <img>
in React and convert the image content into its base64 text representation?
I have seen various solutions on Stack Overflow. Some of these solutions attempt to retrieve the image from a URL again (which caused CORS issues in my case and also represents redundant loading). E.g. I have looked here: Convert image from url to Base64
If I wanted to implement this solution I would not know how to do so in a React environment:
- I don't know how this
document.getElementById("imageid")
works in a React environment; and - I would also not know where to place the function in React that is supposed to draw a canvas.