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

Function compressImageBlock

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

Source from the content-addressed store, hash-verified

598 * Wrapper around compressImageBuffer for ImageBlockParam.
599 */
600export async function compressImageBlock(
601 imageBlock: ImageBlockParam,
602 maxBytes: number = IMAGE_TARGET_RAW_SIZE,
603): Promise<ImageBlockParam> {
604 // Only process base64 images
605 if (imageBlock.source.type !== 'base64') {
606 return imageBlock
607 }
608
609 // Decode base64 to buffer
610 const imageBuffer = Buffer.from(imageBlock.source.data, 'base64')
611
612 // Check if already within size limit
613 if (imageBuffer.length <= maxBytes) {
614 return imageBlock
615 }
616
617 // Compress the image
618 const compressed = await compressImageBuffer(imageBuffer, maxBytes)
619
620 return {
621 type: 'image',
622 source: {
623 type: 'base64',
624 media_type: compressed.mediaType,
625 data: compressed.base64,
626 },
627 }
628}
629
630// Helper functions for compression pipeline
631

Callers 1

truncateContentBlocksFunction · 0.85

Calls 1

compressImageBufferFunction · 0.85

Tested by

no test coverage detected