MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / compressImageBlock

Function compressImageBlock

src/utils/imageResizer.ts:615–643  ·  view source on GitHub ↗
(
  imageBlock: ImageBlockParam,
  maxBytes: number = IMAGE_TARGET_RAW_SIZE,
)

Source from the content-addressed store, hash-verified

613 * Wrapper around compressImageBuffer for ImageBlockParam.
614 */
615export async function compressImageBlock(
616 imageBlock: ImageBlockParam,
617 maxBytes: number = IMAGE_TARGET_RAW_SIZE,
618): Promise<ImageBlockParam> {
619 // Only process base64 images
620 if (imageBlock.source.type !== 'base64') {
621 return imageBlock
622 }
623
624 // Decode base64 to buffer
625 const imageBuffer = Buffer.from(imageBlock.source.data, 'base64')
626
627 // Check if already within size limit
628 if (imageBuffer.length <= maxBytes) {
629 return imageBlock
630 }
631
632 // Compress the image
633 const compressed = await compressImageBuffer(imageBuffer, maxBytes)
634
635 return {
636 type: 'image',
637 source: {
638 type: 'base64',
639 media_type: compressed.mediaType,
640 data: compressed.base64,
641 },
642 }
643}
644
645// Helper functions for compression pipeline
646

Callers 1

truncateContentBlocksFunction · 0.85

Calls 1

compressImageBufferFunction · 0.85

Tested by

no test coverage detected