MCPcopy
hub / github.com/jimp-dev/jimp / read

Method read

packages/core/src/index.ts:234–264  ·  view source on GitHub ↗

* Create a Jimp instance from a URL, a file path, or a Buffer * @example * ```ts * import { Jimp } from "jimp"; * * // Read from a file path * const image = await Jimp.read("test/image.png"); * * // Read from a URL * const image = await Jimp.read("https:/

(
      url: string | Buffer | ArrayBuffer,
      options?: MimeTypeToDecodeOptions
    )

Source from the content-addressed store, hash-verified

232 * ```
233 */
234 static async read(
235 url: string | Buffer | ArrayBuffer,
236 options?: MimeTypeToDecodeOptions
237 ) {
238 if (Buffer.isBuffer(url) || url instanceof ArrayBuffer) {
239 return this.fromBuffer(url);
240 }
241
242 if (existsSync(url)) {
243 return this.fromBuffer(await readFile(url));
244 }
245
246 const [fetchErr, response] = await to(fetch(url));
247
248 if (fetchErr) {
249 throw new Error(`Could not load Buffer from URL: ${url}`);
250 }
251
252 if (!response.ok) {
253 throw new Error(`HTTP Status ${response.status} for url ${url}`);
254 }
255
256 const [arrayBufferErr, data] = await to(response.arrayBuffer());
257
258 if (arrayBufferErr) {
259 throw new Error(`Could not load Buffer from ${url}`);
260 }
261
262 const buffer = bufferFromArrayBuffer(data);
263 return this.fromBuffer(buffer, options);
264 }
265
266 /**
267 * Create a Jimp instance from a bitmap.

Callers 15

GrayscaleExampleFunction · 0.80
WebpExampleFunction · 0.80
imageWithOrientationFunction · 0.80
imageWithOrientation2Function · 0.80
jimp.test.tsFile · 0.80
index.node.test.tsFile · 0.80
createCatFunction · 0.80
index.test.tsFile · 0.80
index.test.tsFile · 0.80
index.test.tsFile · 0.80
index.node.test.tsFile · 0.80

Calls 2

fromBufferMethod · 0.95
bufferFromArrayBufferFunction · 0.85

Tested by 3

imageWithOrientationFunction · 0.64
imageWithOrientation2Function · 0.64
createCatFunction · 0.64