Hi, I tried to upload an image from a URL, but from what I see it doesn’t work, only for images that I place locally.
The purpose of uploading images using URL is because in the JSON I receive it contains their URL.
Example:
let img;
function preload () {
img = 'https://digimon.shadowsmith.com/img/koromon.jpg';
}
function setup () {
createCanvas (400, 400);
image (img, 0, 0, width, height);
}
function draw () {
background (220);
}
This produces the error:
Uncaught TypeError: Failed to execute ‘drawImage’ on ‘CanvasRenderingContext2D’: The provided value is not of type ‘(CSSImageValue or HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)’ (sketch: line 8)
The image command (img, 0, 0, width, height) should accept the URL parameter as well, not just local referencing.
Using with LoadImage also ends up giving an error:
let img;
function preload () {
img = loadImage ('https://digimon.shadowsmith.com/img/koromon.jpg');
}
function setup () {
createCanvas (400, 400);
image (img, 0, 0, width, height);
}
function draw () {
background (220);
}
The error that da is this:
p5.js says: It looks like there was a problem loading your image. Try checking if the file path [https://digimon.shadowsmith.com/img/koromon.jpg] is correct, hosting the image online, or running a local server. [Https://github.com/processing/p5. js / wiki / Local-server]
Event {isTrusted: true, constructor: Object}
Hello friend, this way it works smoothly, but that’s not what I want.
I want to upload the image with just the URL, not using it locally … why do I want this ??, why do I get the URL path via JSON, so I need it to work with the URL.
Using it that way doesn’t work either.
And the problem is not the image, why using another of the same. I’m starting to believe this is an uncataloged bug.
let img;
function setup () {
createCanvas (400, 400);
loadImage('https://digimon.shadowsmith.com/img/koromon.jpg', img => {
image(img, 0, 0, width, height);
});
}
function draw () {
background (220);
}
look in your inspect console
( i am on win 10 / browser firefox )
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://digimon.shadowsmith.com/img/koromon.jpg. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).