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

Function compressImageBufferWithTokenLimit

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

Source from the content-addressed store, hash-verified

596 * Converts tokens to bytes using the formula: maxBytes = (maxTokens / 0.125) * 0.75
597 */
598export async function compressImageBufferWithTokenLimit(
599 imageBuffer: Buffer,
600 maxTokens: number,
601 originalMediaType?: string,
602): Promise<CompressedImageResult> {
603 // Convert token limit to byte limit
604 // base64 uses about 4/3 the original size, so we reverse this
605 const maxBase64Chars = Math.floor(maxTokens / 0.125)
606 const maxBytes = Math.floor(maxBase64Chars * 0.75)
607
608 return compressImageBuffer(imageBuffer, maxBytes, originalMediaType)
609}
610
611/**
612 * 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