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

Method getBuffer

packages/core/src/index.ts:424–453  ·  view source on GitHub ↗

* Converts the Jimp instance to an image buffer * @param mime The mime type to export to * @param options The options to use when exporting * @example * ```ts * import { Jimp } from "jimp"; * import { promises as fs } from "fs"; * * const image = new Jimp({ wi

(mime: ProvidedMimeType, options?: Options)

Source from the content-addressed store, hash-verified

422 * ```
423 */
424 async getBuffer<
425 ProvidedMimeType extends SupportedMimeTypes,
426 Options extends GetOptionsForMimeType<
427 ProvidedMimeType,
428 MimeTypeToExportOptions
429 >,
430 >(mime: ProvidedMimeType, options?: Options) {
431 const format = this.formats.find((format) => format.mime === mime);
432
433 if (!format || !format.encode) {
434 throw new Error(`Unsupported MIME type: ${mime}`);
435 }
436
437 let outputImage: Jimp;
438
439 if (format.hasAlpha) {
440 // eslint-disable-next-line @typescript-eslint/no-this-alias
441 outputImage = this;
442 } else {
443 outputImage = new CustomJimp({
444 width: this.bitmap.width,
445 height: this.bitmap.height,
446 color: this.background,
447 });
448
449 composite(outputImage, this);
450 }
451
452 return format.encode(outputImage.bitmap, options);
453 }
454
455 /**
456 * Converts the image to a base 64 string

Callers 15

getBase64Method · 0.95
writeMethod · 0.95
exif.node.test.tsFile · 0.80
index.node.test.tsFile · 0.80
index.test.tsFile · 0.80
index.test.tsFile · 0.80
index.node.test.tsFile · 0.80
index.test.tsFile · 0.80
index.test.tsFile · 0.80

Calls 1

compositeFunction · 0.85

Tested by 1

createTextImageFunction · 0.64