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

Function compressImageBlock

source code/utils/imageResizer.ts:602–630  ·  view source on GitHub ↗
(
  imageBlock: ImageBlockParam,
  maxBytes: number = IMAGE_TARGET_RAW_SIZE,
)

Source from the content-addressed store, hash-verified

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

Callers 1

truncateContentBlocksFunction · 0.85

Calls 1

compressImageBufferFunction · 0.85

Tested by

no test coverage detected