How to read loaded image into a blob?

Posted by Gajus Kuizinas on Stack Overflow See other posts from Stack Overflow or by Gajus Kuizinas
Published on 2012-12-18T16:38:15Z Indexed on 2012/12/18 17:03 UTC
Read the original article Hit count: 142

Filed under:
|

I am facing same-origin policy restrictions when loading remote images. However DOM 0 Image object can be used to load a remote resource (this is essentially the same as creating an <img /> tag).

var fr = new FileReader(),
    img = new Image();

img.src = 'http://distilleryimage8.s3.amazonaws.com/6cf25568491a11e2af8422000a9e28e9_7.jpg';

img.onload = function () {
    // how to get this image as a Blob object?
};

Is there a way to read this resource into a Blob/arraybuffer object? This is not a duplicate of How to convert an image object to a binary blob as the latter does not rise with same-origin issues.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html5