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

84
Visualizações
iOS resizing image with canvas results in black image

I am trying to resize multiple images in the browser (same results in Chrome and Safari) by using canvas, to then save them to IndexedDB via Dexie.js. It all works fine in Android, but on iOS (tested on iPhone 8 and X) 1 or 2 random pictures result in black images. What might be the issue? This is the function I am using:

photoHeightMax = 1100;
photoWidthMax = 1100;

    resizeBase64Img(src) {
    return new Promise((resolve, reject) => {
      const img = new Image();
      img.src = src;
      img.onload = () => {
        const imgWidth = img.width;
        const imgHeight = img.height;
        const scale = Math.min(this.photoWidthMax / imgWidth, this.photoHeightMax / imgHeight);

        const widthScaled = scale > 1 ? imgWidth : imgWidth * scale;
        const heightScaled = scale > 1 ? imgHeight : imgHeight * scale;

        const elem = document.createElement('canvas');
        elem.width = widthScaled;
        elem.height = heightScaled;
        const ctx = elem.getContext('2d');
        ctx.drawImage(img, 0, 0, widthScaled, heightScaled);
        const data = ctx.canvas.toDataURL('image/jpeg', 0.85);
        resolve(data);
      };
      img.onerror = (error) => reject(error);
    });
  }

Any help would be appreciated!

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