( context: ImageCompressionContext, quality: number, sharp: SharpFunction, )
| 738 | } |
| 739 | |
| 740 | async function tryJPEGConversion( |
| 741 | context: ImageCompressionContext, |
| 742 | quality: number, |
| 743 | sharp: SharpFunction, |
| 744 | ): Promise<CompressedImageResult | null> { |
| 745 | const jpegBuffer = await sharp(context.imageBuffer) |
| 746 | .resize(600, 600, { |
| 747 | fit: 'inside', |
| 748 | withoutEnlargement: true, |
| 749 | }) |
| 750 | .jpeg({ quality }) |
| 751 | .toBuffer() |
| 752 | |
| 753 | if (jpegBuffer.length <= context.maxBytes) { |
| 754 | return createCompressedImageResult(jpegBuffer, 'jpeg', context.originalSize) |
| 755 | } |
| 756 | |
| 757 | return null |
| 758 | } |
| 759 | |
| 760 | async function createUltraCompressedJPEG( |
| 761 | context: ImageCompressionContext, |
no test coverage detected