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

Function resizeShellImageOutput

src/tools/BashTool/utils.ts:110–131  ·  view source on GitHub ↗
(
  stdout: string,
  outputFilePath: string | undefined,
  outputFileSize: number | undefined,
)

Source from the content-addressed store, hash-verified

108 * parse as a data URI (caller decides whether to flip isImage).
109 */
110export async function resizeShellImageOutput(
111 stdout: string,
112 outputFilePath: string | undefined,
113 outputFileSize: number | undefined,
114): Promise<string | null> {
115 let source = stdout
116 if (outputFilePath) {
117 const size = outputFileSize ?? (await stat(outputFilePath)).size
118 if (size > MAX_IMAGE_FILE_SIZE) return null
119 source = await readFile(outputFilePath, 'utf8')
120 }
121 const parsed = parseDataUri(source)
122 if (!parsed) return null
123 const buf = Buffer.from(parsed.data, 'base64')
124 const ext = parsed.mediaType.split('/')[1] || 'png'
125 const resized = await maybeResizeAndDownsampleImageBuffer(
126 buf,
127 buf.length,
128 ext,
129 )
130 return `data:image/${resized.mediaType};base64,${resized.buffer.toString('base64')}`
131}
132
133export function formatOutput(content: string): {
134 totalLines: number

Callers 2

callFunction · 0.85
callFunction · 0.85

Calls 5

statFunction · 0.85
readFileFunction · 0.85
parseDataUriFunction · 0.85
toStringMethod · 0.65

Tested by

no test coverage detected