( context: ImageCompressionContext, quality: number, sharp: SharpFunction, )
| 723 | } |
| 724 | |
| 725 | async function tryJPEGConversion( |
| 726 | context: ImageCompressionContext, |
| 727 | quality: number, |
| 728 | sharp: SharpFunction, |
| 729 | ): Promise<CompressedImageResult | null> { |
| 730 | const jpegBuffer = await sharp(context.imageBuffer) |
| 731 | .resize(600, 600, { |
| 732 | fit: 'inside', |
| 733 | withoutEnlargement: true, |
| 734 | }) |
| 735 | .jpeg({ quality }) |
| 736 | .toBuffer() |
| 737 | |
| 738 | if (jpegBuffer.length <= context.maxBytes) { |
| 739 | return createCompressedImageResult(jpegBuffer, 'jpeg', context.originalSize) |
| 740 | } |
| 741 | |
| 742 | return null |
| 743 | } |
| 744 | |
| 745 | async function createUltraCompressedJPEG( |
| 746 | context: ImageCompressionContext, |
no test coverage detected