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

274
Views
fabric.js canvas background image won't load until an object is clicked

I'm trying to set an image as a background for a canvas but the image won't load until until an object(rectangle) is clicked on the canvas.

Did someone has the same problem?

var canvas = new fabric.Canvas('image_canvas');
canvas.setWidth(window.innerWidth * factor);
canvas.setHeight(window.innerWidth / 2 * factor);
var canvasHeight = canvas.height;
var canvasWidth = canvas.width;

//Just a debug statement console.log(canvasWidth, canvasHeight);

var bgImg = new fabric.Image();
bgImg.setSrc('<?= $image_src ?>', function () {
   bgImg.set({
      top: 0,
      left: 0,
      scaleX: canvasWidth / bgImg.width,
      scaleY: canvasHeight / bgImg.height,
   });
});
canvas.setBackgroundImage(bgImg, canvas.renderAll.bind(canvas));
canvas.renderAll();
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!