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

Function getImageProcessor

src/tools/FileReadTool/imageProcessor.ts:37–67  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35let imageCreatorModule: { default: SharpCreator } | null = null
36
37export async function getImageProcessor(): Promise<SharpFunction> {
38 if (imageProcessorModule) {
39 return imageProcessorModule.default
40 }
41
42 if (isInBundledMode()) {
43 // Try to load the native image processor first
44 try {
45 // Use the native image processor module
46 const imageProcessor = await import('image-processor-napi')
47 const sharp = imageProcessor.sharp || imageProcessor.default
48 imageProcessorModule = { default: sharp }
49 return sharp
50 } catch {
51 // Fall back to sharp if native module is not available
52 // biome-ignore lint/suspicious/noConsole: intentional warning
53 console.warn(
54 'Native image processor not available, falling back to sharp',
55 )
56 }
57 }
58
59 // Use sharp for non-bundled builds or as fallback.
60 // Single structural cast: our SharpFunction is a subset of sharp's actual type surface.
61 const imported = (await import(
62 'sharp'
63 )) as unknown as MaybeDefault<SharpFunction>
64 const sharp = unwrapDefault(imported)
65 imageProcessorModule = { default: sharp }
66 return sharp
67}
68
69/**
70 * Get image creator for generating new images from scratch.

Callers 4

compressImageBufferFunction · 0.85
getImageFromClipboardFunction · 0.85
tryReadImageFromPathFunction · 0.85

Calls 3

isInBundledModeFunction · 0.85
unwrapDefaultFunction · 0.85
warnMethod · 0.45

Tested by

no test coverage detected