Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
DiscordJS/Canvas - Setting src on Canvas.Image() not working

I'm trying to preload a number of images, prior to drawing them using Canvas. I've googled, and read and managed to find some code (with revisions) to cycle through a list of URLs. However, I can't seem to be able to set the housing_image.src to a URL within the list.

Using console.log I can see that the URL is reporting correctly, but when I assign it to the hosuing_image.src the console.log appears blank.

Hopefully it is something super simple that I am missing...

const imageURL = ["https://syrathos.net/other/sale_sign.png","https://syrathos.net/other/housing_1.png"];
    const images = [];
    var imageCount = 0;

function allLoaded(){
    context.drawImage(images[1],0,0);
    context.drawImage(images[0],0,0);
}

for (const URL of imageURL) {
     const housing_image = new Canvas.Image();    
     housing_image.onload = ()=>{ 
        console.log("loaded : " + housing_image.src)
         imageCount += 1;
         if(imageCount === imageURL.length){
             allLoaded();
         }
     }
     console.log(URL)
     housing_image.src = URL;
     images.push(housing_image);
     console.log(housing_image.src);

};

Console Log

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!