Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

323
Visualizações
Why canvas image size break in Safari?

First, the website width and height is based on the user screen.

var c = document.getElementById("canvas");
var ctx = c.getContext("2d");

c.width = window.innerWidth;
c.height = window.innerHeight;

window.addEventListener("resize", function () {
    c.width = window.innerWidth;
    c.height = window.innerHeight;
})

Then, I am using drawImage

class castle {
    constructor() {
        const castle = new Image()
        castle.src = './Img/castle.png'

        castle.onload = () => {
            this.scale = 0.5
            this.image = castle
            this.width = this.image.width * this.scale
            this.height = this.image.height * this.scale
            this.position = {
                x: c.width / 2 - this.width / 2,
                y: c.height / 2 - this.height / 2
            }

            this.center = {
                x: c.width / 2,
                y: c.height / 2
            }
        }

    }

    draw() {
        ctx.drawImage(
            this.image,
            this.position.x,
            this.position.y,
            this.width,
            this.height
        )
    }
}

Same monitor:

Why the image shown different size between Google Chrome and Safari?

The performance of my project with Google Chrome is fine. However, the image size with Safari is too too big

I googled: image to canvas on chrome but not safari

Em... Should I upload all image to imgur? It's better than open a folder Img in my project?

about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda