Manak Kapoor
Manak Kapoor

Reputation: 982

AJAXing Images and dealing with it's data

jQuery.ajax({
  url: "http://img.bitpixels.com/getthumbnail?code=72853&size=200&url=http://www.facebook.com"}).done(function ( data ) {
        if( console && console.log ) {
            magically_display(data)
        }
    });

So i've got as far as to ajaxing images. Now im confused, is it possible to display the image without getting a base64 encoded version from the server? I don't want to use the Image Object to load the image, nor do i want to put the url directly into an image tag, my purpose for this is to find a way to encode the image into a format which i can save in localstorage and later display using javascript.

Any ideas guys?

Upvotes: 2

Views: 75

Answers (1)

Dmitry Volokh
Dmitry Volokh

Reputation: 1646

https://developer.mozilla.org/en-US/docs/DOM/Storage

interface Storage {
  readonly attribute unsigned long length;
  [IndexGetter] DOMString key(in unsigned long index);
  [NameGetter] DOMString getItem(in DOMString key);
  [NameSetter] void setItem(in DOMString key, in DOMString data);
  [NameDeleter] void removeItem(in DOMString key);
  void clear();
};

LocalStorage allows to save only String values. So, you must to "convert" your image to text and "convert it back" for current usecase. Guess, base64 is the best solution.

Upvotes: 2

Related Questions