MCPcopy Index your code
hub / github.com/codeaashu/claude-code / tryProgressiveResizing

Function tryProgressiveResizing

src/utils/imageResizer.ts:646–680  ·  view source on GitHub ↗
(
  context: ImageCompressionContext,
  sharp: SharpFunction,
)

Source from the content-addressed store, hash-verified

644}
645
646async function tryProgressiveResizing(
647 context: ImageCompressionContext,
648 sharp: SharpFunction,
649): Promise<CompressedImageResult | null> {
650 const scalingFactors = [1.0, 0.75, 0.5, 0.25]
651
652 for (const scalingFactor of scalingFactors) {
653 const newWidth = Math.round(
654 (context.metadata.width || 2000) * scalingFactor,
655 )
656 const newHeight = Math.round(
657 (context.metadata.height || 2000) * scalingFactor,
658 )
659
660 let resizedImage = sharp(context.imageBuffer).resize(newWidth, newHeight, {
661 fit: 'inside',
662 withoutEnlargement: true,
663 })
664
665 // Apply format-specific optimizations
666 resizedImage = applyFormatOptimizations(resizedImage, context.format)
667
668 const resizedBuffer = await resizedImage.toBuffer()
669
670 if (resizedBuffer.length <= context.maxBytes) {
671 return createCompressedImageResult(
672 resizedBuffer,
673 context.format,
674 context.originalSize,
675 )
676 }
677 }
678
679 return null
680}
681
682function applyFormatOptimizations(
683 image: SharpInstance,

Callers 1

compressImageBufferFunction · 0.85

Calls 3

applyFormatOptimizationsFunction · 0.85
resizeMethod · 0.45

Tested by

no test coverage detected