// Downsize if image exceeds 1920x1080 (2,073,600 pixels) const MAX_PIXELS = 1920 * 1080; // 2,073,600 pixels const currentPixels = img.width * img.height; let imgWidth = img.width; let imgHeight = img.height; if (currentPixels > MAX_PIXELS) { const scale = Math.sqrt(MAX_PIXELS / currentPixels); imgWidth = Math.round(img.width * scale); imgHeight = Math.round(img.height * scale); console.log(`Downsizing image from ${img.width}x${img.height} (${currentPixels} px) to ${imgWidth}x${imgHeight} (${imgWidth * imgHeight} px)`); }