0

I would like to save an image to reuse it on several pages. The simplest way for me would be to use local storage.

Now, I'm wondering if it is a safe option. I'm not sure about the size of the generated image, so I'm afraid that it could sometimes exceed the limit of the local storage capacity.

If it can help, here are the characteristics of a typical image:

  • 980x653 PNG
  • When saved, it weighs ~400ko
  • base64 is ~33k chars (but I guess it can easily double)
benomatis
  • 5,536
  • 7
  • 36
  • 59
saawsann
  • 625
  • 1
  • 6
  • 17

1 Answers1

2

Checkout this question:

How to store and retrieve image to localStorage?

It should provide you with more insight to what the best way to achieve this is. If you can guarentee that the image won't be greater than 5mb then go ahead! You could always do some validation to check whether it's too large. You could also compress the image if it's too big and then save it, although quality will be lost.

Community
  • 1
  • 1
James111
  • 15,378
  • 15
  • 78
  • 121
  • Thanks for the answer. Actually, storing/retrieving the image is not an issue in itself. It is more, do I need to worry that my images would be larger than 5mb? – saawsann Mar 24 '16 at 12:37
  • 1
    Umm..Well it depends where you're getting the images from. If users are uploading them then, yeah you do need to worry about the size (maybe add some validation & image compression in this case). If you can guarantee that the images wont be > 5mb, then whats the point of worrying? But if you're unsure then it's worth adding some validation or image compression in your code. @saawsann – James111 Mar 25 '16 at 00:35