I’m running into a JavaScript issue where an async function is supposed to load an image (edited in photo editing software like Meitu, Adobe Lightroom, Illustrator) and then apply additional processing, but it doesn’t seem to be waiting for the image to fully load before moving to the next step. Here’s the function:
async function loadImageAndProcess(url) {
try {
const response = await fetch(url);
const blob = await response.blob();
const img = new Image();
img.src = URL.createObjectURL(blob);
img.onload = () => {
console.log("Image loaded:", img);
// Further image processing here
};
} catch (error) {
console.error("Error loading image:", error);
}
}
The issue is that img.onload
sometimes fires inconsistently, especially with large images edited in external software. I’ve tried adding more await calls, but it hasn’t resolved the issue. Has anyone else had issues with async image loading in JavaScript, especially for large, edited images?