Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I grab a single image and put it in localStorage?

How is it done, of course without external libraries, in regular HTML with JavaScript? This seems like it should be a simple one-liner.

I'd like to just do:

<script>
localStorage.image=src("http://"+randomflikrimage+".jpg")
</script>
like image 455
David Avatar asked May 15 '11 07:05

David


People also ask

How do I upload photos to localStorage?

As we established above, localStorage only supports strings, so what we need to do here is turn the image into a Data URL. One way to do this for an image, is to load into a canvas element. Then, with a canvas , you can read out the current visual representation in a canvas as a Data URL.

Can local storage store image?

Only string values can be stored in local storage - this will not be a problem, and we'll see in this post how we'll store a collection of images along with some data for each.


1 Answers

Try storing base64 data, use canvas. Check this: Get image data in JavaScript?

like image 113
spacevillain Avatar answered Oct 05 '22 01:10

spacevillain