Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda