* 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)
| 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 |