MCPcopy
hub / github.com/imgly/background-removal-js / imageSourceToImageData

Function imageSourceToImageData

packages/node/src/utils.ts:106–124  ·  view source on GitHub ↗
(
  image: ImageSource,
  _: Config
)

Source from the content-addressed store, hash-verified

104}
105
106async function imageSourceToImageData(
107 image: ImageSource,
108 _: Config
109): Promise<NdArray<Uint8Array>> {
110 if (typeof image === 'string') {
111 image = ensureAbsoluteURI(image, `file://${process.cwd()}/`);
112 }
113 if (image instanceof URL) {
114 image = await (await loadFromURI(image)).blob();
115 }
116 if (image instanceof ArrayBuffer || ArrayBuffer.isView(image)) {
117 image = new Blob([image]);
118 }
119 if (image instanceof Blob) {
120 image = await codecs.imageDecode(image);
121 }
122
123 return image as NdArray<Uint8Array>;
124}
125
126function convertFloat32ToUint8(
127 float32Array: NdArray<Float32Array>

Callers

nothing calls this directly

Calls 2

ensureAbsoluteURIFunction · 0.90
loadFromURIFunction · 0.90

Tested by

no test coverage detected