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

Function tryPalettePNG

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

Source from the content-addressed store, hash-verified

700}
701
702async 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
725async function tryJPEGConversion(
726 context: ImageCompressionContext,

Callers 1

compressImageBufferFunction · 0.85

Calls 2

resizeMethod · 0.45

Tested by

no test coverage detected