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

86
Views
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
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!