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

141
Views
Canvas not being drawn after move to Laravel

I have a project that has been written without a framework and works fine. Photos are displayed on a page. Clicking on one opens a modal and the image is displayed on a canvas in the modal.

This is the javascript used to open the modal imageModal and draw the photo onto the canvas called photoImage, with e being the image that has been clicked on.

var canvas = document.getElementById("photoImage");
var canvasCtx = canvas.getContext("2d");

function viewPhoto(e) {
    $("#imageModal").modal("show");

    var image = new Image();
    image.src = e.src;

    canvas.width = image.width; // Width does not get set 
    canvas.height = image.height;  // Height does not get set 
    canvasCtx.drawImage(image, 0, 0);  // Photo does not get drawn
}

I have now used the exact same code in a Laravel project but it does not draw the picture onto the canvas. I have checked the properties of the canvas in both projects and they are the same.

For example the canvas is picking up th height property correctly in both projects but it does not change the size of the canvas in the Laravel project.

enter image description here

What could be causing the problem?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

var canvas = document.getElementById("photoImage")[0]; //it return an array of object 
var canvasCtx = canvas.getContext("2d");  
canvasCtx.drawImage(image, 6, 6);  // Photo does not get drawn

also you can use typeo canvas.getContext('2d').drawImage(img, 6, 6)

about 4 years ago · Juan Pablo Isaza Report
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!