xxxxxxxxxx
41
// https://discourse.processing.org/t/how-to-upload-an-image-from-a-url/16020/3
// on win 10 firefox browser install https://addons.mozilla.org/en-US/firefox/addon/cors-everywhere/
let url = "https://digimon.shadowsmith.com/img/koromon.jpg";
let img_remote, img;
let lucky = false;
function preload() {
//img = loadImage ("https://digimon.shadowsmith.com/img/koromon.jpg");
img = loadImage("assets/koromon.jpg");
}
function setup() {
createCanvas(400, 400);
img.resize(400, 400); //_ do not resize a image every draw loop, better here once
}
function draw() {
// background(img); // optional OR
background(200, 200, 0); // default
if (lucky) image(img_remote, 0, 0);
else text("use key [ l ]", 20, 20);
}
function keyPressed() {
if (key == 'l') {
img_remote = loadImage(url, gotit, failed);
print("try load " + url);
}
}
function gotit() {
lucky = true;
img_remote.resize(400, 400);
print("ok...");
}
function failed() {
print("hmmm");
}