MCPcopy
hub / github.com/codeaashu/claude-code / compressImageBufferWithTokenLimit

Function compressImageBufferWithTokenLimit

src/utils/imageResizer.ts:583–594  ·  view source on GitHub ↗
(
  imageBuffer: Buffer,
  maxTokens: number,
  originalMediaType?: string,
)

Source from the content-addressed store, hash-verified

581 * Converts tokens to bytes using the formula: maxBytes = (maxTokens / 0.125) * 0.75
582 */
583export async function compressImageBufferWithTokenLimit(
584 imageBuffer: Buffer,
585 maxTokens: number,
586 originalMediaType?: string,
587): Promise<CompressedImageResult> {
588 // Convert token limit to byte limit
589 // base64 uses about 4/3 the original size, so we reverse this
590 const maxBase64Chars = Math.floor(maxTokens / 0.125)
591 const maxBytes = Math.floor(maxBase64Chars * 0.75)
592
593 return compressImageBuffer(imageBuffer, maxBytes, originalMediaType)
594}
595
596/**
597 * Compresses an image block to fit within a maximum byte size.

Callers 1

readImageWithTokenBudgetFunction · 0.85

Calls 1

compressImageBufferFunction · 0.85

Tested by

no test coverage detected