我通常使用
http://imgur.com/的图像(与SO使用的内联图像相同的网站) – 无需注册,只需上传或粘贴到图像链接中即可.
它支持CORS要求,因此您可以直接链接并使用canvas进行像素提取.
如果您需要托管不同的文件,除了图像我建议DropBox作为markE.
然而,有任何免费服务包括. ImgUr和DropBox,所以在使用链接之前,请务必阅读使用条款(ToS)(即,它们都不会用作CDN,因此您可能想查看一些商业CDN提供商).
启用CORS使用
如果允许,您可以在JavaScript中设置 – 在设置src之前设置crossOrigin:
var img = new Image();
img.crossOrigin = ""; // or "anonymous",will be interpreted the same
...
img.src = "...";
作为HTML标签的属性(顺序无关紧要):
测试
var img = new Image();
img.crossOrigin = "";
img.onload = test;
img.src = "http://i.imgur.com/fHyEMsl.jpg";
function test() {
var ctx = document.querySelector("canvas").getContext("2d");
ctx.drawImage(this,0);
// This will fail if no CORS support,otherwise all OK
try {
ctx.getImageData(0,10,10);
alert("All OK");
}
catch(err) {
alert("No CORS support...");
}
}