···4949 if (!ctx) return reject(new Error('Failed to get canvas context.'));
5050 ctx.drawImage(img, 0, 0, width, height);
51515252- // Use WebP for both compression and transparency support
5252+ // Use WebP if supported, fall back to JPEG (Safari doesn't support WebP encoding)
5353+ const supportsWebP = canvas.toDataURL('image/webp').startsWith('data:image/webp');
5454+ const mimeType = supportsWebP ? 'image/webp' : 'image/jpeg';
5355 let quality = 0.9;
54565557 function attemptCompression() {
···7173 attemptCompression();
7274 }
7375 },
7474- 'image/webp',
7676+ mimeType,
7577 quality
7678 );
7779 }