Every now and then I happen to come across JS questions that involve canvases and images in some way.
When attempting to answer, I usually create a runnable snippet.
Now, because of same-origin-policy, any images I use will "taint" the canvas, thus breaking some functionality I sometimes require.
That is, unless I manage to get a CORS enabled image, and here's the point:
On i.imgur.com
, images are CORS-enabled.
On i.stack.imgur.com
however (which is used for image uploads from the editor), images are not CORS-enabled.
Demo:
i.imgur.com
:
var i = new Image();
i.crossOrigin = '';
i.onload = function() {
document.write('Image loaded successfully');
};
i.onerror = function(e) {
document.write('Error loading image');
};
i.src = 'https://i.sstatic.net/i8e7s.jpg';
i.stack.imgur.com
(only last line changed):
var i = new Image();
i.crossOrigin = '';
i.onload = function() {
document.write('Image loaded successfully');
};
i.onerror = function(e) {
document.write('Error loading image');
};
i.src = 'https://i.sstatic.net/PORPF.jpg';
And just for the record, both images are present:
one:
and two:
Could this be changed please?
Sure, I could just use "regular" Imgur as a workaround, but then what would be the point of Stack's Imgur account?
And I imagine if anyone can make this change happen, it's the folks at SE, so I'm asking you:
Can i.stack.imgur.com
please be CORS-enabled?
data:image/base64;...
for this purpose? Strangely enough both of your example show Image loaded successfully so now I'm even more confused...