( context: ImageCompressionContext, sharp: SharpFunction, )
| 700 | } |
| 701 | |
| 702 | async function tryPalettePNG( |
| 703 | context: ImageCompressionContext, |
| 704 | sharp: SharpFunction, |
| 705 | ): Promise<CompressedImageResult | null> { |
| 706 | const palettePng = await sharp(context.imageBuffer) |
| 707 | .resize(800, 800, { |
| 708 | fit: 'inside', |
| 709 | withoutEnlargement: true, |
| 710 | }) |
| 711 | .png({ |
| 712 | compressionLevel: 9, |
| 713 | palette: true, |
| 714 | colors: 64, // Reduce colors to 64 for better compression |
| 715 | }) |
| 716 | .toBuffer() |
| 717 | |
| 718 | if (palettePng.length <= context.maxBytes) { |
| 719 | return createCompressedImageResult(palettePng, 'png', context.originalSize) |
| 720 | } |
| 721 | |
| 722 | return null |
| 723 | } |
| 724 | |
| 725 | async function tryJPEGConversion( |
| 726 | context: ImageCompressionContext, |
no test coverage detected