Initial commit

This commit is contained in:
robert committed 2025-05-30 18:13:30 +08:00
commit e49726988c
5445 files changed
+1089914

No files matched your search

+1904
View File
File diff suppressed because it is too large. Load diff
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAQ9D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAuBvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,cAAc,sBAAsB,CAAC;AAErC,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,iBAAiB,GAAG,MAAM,EAAE,CAAC;CAC1D;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,4BAA4B,CAAC;AAE3E,6DAA6D;AAC7D,KAAK,kBAAkB,CAAC,aAAa,EAAE,SAAS,EAAE,MAAM,IACtD,MAAM,SAAS,mBAAmB,CAAC,MAAM,IAAI,CAAC,GAC1C,CACE,GAAG,IAAI,EAAE,IAAI,KACV,mBAAmB,CAAC,aAAa,EAAE,SAAS,CAAC,GAAG,aAAa,GAClE,MAAM,SAAS,UAAU,CAAC,MAAM,IAAI,EAAE,MAAM,MAAM,CAAC,GACjD,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,GACzB,KAAK,CAAC;AAEd,mFAAmF;AACnF,MAAM,MAAM,mBAA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IAriBH;;;;;;;;;;;;OAYG;cAEI,MAAM,GAAG,MAAM,GAAG,WAAW;QAtEpC;;WAEG;gBACK,MAAM;QAEd,2CAA2C;;QAG3C,yCAAyC;iBAChC,MAAM,CAAC,GAAG,CAAC,EAAE;QAEtB,0CAA0C;eACnC,MAAM;QA+Lb;;;;;;;;;;;WAWG;;QAWH;;;WAGG;;QAKH,iCAAiC;;QAKjC,kCAAkC;;QAKlC;;;;;;;;;;;;;;;WAeG;kBAED,gBAAgB,8CAChB,OAAO;QA6BT;;;;;;;;;;;;;;;;;;;WAmBG;kBAED,gBAAgB,8CAChB,OAAO;QAST;;;;;;;;;;;;;;;;WAgBG;cAED,SAAS,SAAS,MAAM,EACxB,IAAI,6GACJ,OAAO;QAST;;;;;;;;;;;;WAYG;cACG,CAAC;QAOP;;;;;;;;;;;;;;WAcG;yBACc,MAAM,KAAK,MAAM,iBAAiB,IAAI;QAyDvD;;;;;;;;;;;;;WAaG;yBACc,MAAM,KAAK,MAAM;QASlC;;;;;;;;;;;;;;;WAeG;2BACgB,MAAM,KAAK,MAAM,KAAK,MAAM;QAe/C;;;;;;;;;;;;;WAaG;;QAcH;;;;;;;;;;;;;;;WAeG;kBACO,CAAC,wDAIA;YACP,IAAI,CAAC,EAAE,SAAS,CAAC;YACjB,aAAa,CAAC,EAAE,MAAM,CAAC;YACvB,WAAW,CAAC,EAAE,MAAM,CAAC;SACtB;QAKH;;;;;;;;;;;;;;;;;;WAkBG;gBACK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,GAAG;QAnBlD;;;;;;;;;;;;;;;;;;WAkBG;gBAGLine truncated
+529
View File
@@ -0,0 +1,529 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.composite = exports.getExifOrientation = void 0;
exports.createJimp = createJimp;
const types_1 = require("@jimp/types");
const utils_1 = require("@jimp/utils");
const core_js_1 = __importDefault(require("file-type/core.js"));
const await_to_js_1 = require("await-to-js");
const file_ops_1 = require("@jimp/file-ops");
const lite_js_1 = __importDefault(require("mime/lite.js"));
const composite_js_1 = require("./utils/composite.js");
const image_bitmap_js_1 = require("./utils/image-bitmap.js");
const emptyBitmap = {
data: Buffer.alloc(0),
width: 0,
height: 0,
};
/**
* Prepare a Buffer object from the arrayBuffer.
*/
function bufferFromArrayBuffer(arrayBuffer) {
const buffer = Buffer.alloc(arrayBuffer.byteLength);
const view = new Uint8Array(arrayBuffer);
for (let i = 0; i < buffer.length; ++i) {
buffer[i] = view[i];
}
return buffer;
}
var image_bitmap_js_2 = require("./utils/image-bitmap.js");
Object.defineProperty(exports, "getExifOrientation", { enumerable: true, get: function () { return image_bitmap_js_2.getExifOrientation; } });
var composite_js_2 = require("./utils/composite.js");
Object.defineProperty(exports, "composite", { enumerable: true, get: function () { return composite_js_2.composite; } });
__exportStar(require("./utils/constants.js"), exports);
/**
* Create a Jimp class that support the given image formats and methods
*/
function createJimp({ plugins: pluginsArg, formats: formatsArg, } = {}) {
const plugins = pluginsArg || [];
const formats = (formatsArg || []).map((format) => format());
const CustomJimp = class Jimp {
/**
* The bitmap data of the image
*/
bitmap = emptyBitmap;
/** Default color to use for new pixels */
background = 0x00000000;
/** Formats that can be used with Jimp */
formats = [];
/** The original MIME type of the image */
mime;
constructor(options = emptyBitmap) {
// Add the formats
this.formats = formats;
if ("data" in options) {
this.bitmap = options;
}
else {
this.bitmap = {
data: Buffer.alloc(options.width * options.height * 4),
width: options.width,
height: options.height,
};
if (options.color) {
this.background =
typeof options.color === "string"
? (0, utils_1.cssColorToHex)(options.color)
: options.color;
for (let i = 0; i < this.bitmap.data.length; i += 4) {
this.bitmap.data.writeUInt32BE(this.background, i);
}
}
}
// Add the plugins
for (const methods of plugins) {
for (const key in methods) {
this[key] = (...args) => {
const result = methods[key]?.(this, ...args);
if (typeof result === "object" && "bitmap" in result) {
this.bitmap = result.bitmap;
return this;
}
return result;
};
}
}
}
/**
* 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://upload.wikimedia.org/wikipedia/commons/0/01/Bot-Test.jpg");
* ```
*/
static async read(url, options) {
if (Buffer.isBuffer(url) || url instanceof ArrayBuffer) {
return this.fromBuffer(url);
}
if ((0, file_ops_1.existsSync)(url)) {
return this.fromBuffer(await (0, file_ops_1.readFile)(url));
}
const [fetchErr, response] = await (0, await_to_js_1.to)(fetch(url));
if (fetchErr) {
throw new Error(`Could not load Buffer from URL: ${url}`);
}
if (!response.ok) {
throw new Error(`HTTP Status ${response.status} for url ${url}`);
}
const [arrayBufferErr, data] = await (0, await_to_js_1.to)(response.arrayBuffer());
if (arrayBufferErr) {
throw new Error(`Could not load Buffer from ${url}`);
}
const buffer = bufferFromArrayBuffer(data);
return this.fromBuffer(buffer, options);
}
/**
* Create a Jimp instance from a bitmap.
* The difference between this and just using the constructor is that this will
* convert raw image data into the bitmap format that Jimp uses.
*
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = Jimp.fromBitmap({
* data: Buffer.from([
* 0xffffffff, 0xffffffff, 0xffffffff,
* 0xffffffff, 0xffffffff, 0xffffffff,
* 0xffffffff, 0xffffffff, 0xffffffff,
* ]),
* width: 3,
* height: 3,
* });
* ```
*/
static fromBitmap(bitmap) {
let data;
if (bitmap.data instanceof Buffer) {
data = Buffer.from(bitmap.data);
}
if (bitmap.data instanceof Uint8Array ||
bitmap.data instanceof Uint8ClampedArray) {
data = Buffer.from(bitmap.data.buffer);
}
if (Array.isArray(bitmap.data)) {
data = Buffer.concat(bitmap.data.map((hex) => Buffer.from(hex.toString(16).padStart(8, "0"), "hex")));
}
if (!data) {
throw new Error("data must be a Buffer");
}
if (typeof bitmap.height !== "number" ||
typeof bitmap.width !== "number") {
throw new Error("bitmap must have width and height");
}
return new CustomJimp({
height: bitmap.height,
width: bitmap.width,
data,
});
}
/**
* Parse a bitmap with the loaded image types.
*
* @param buffer Raw image data
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const buffer = await fs.readFile("test/image.png");
* const image = await Jimp.fromBuffer(buffer);
* ```
*/
static async fromBuffer(buffer, options) {
const actualBuffer = buffer instanceof ArrayBuffer ? bufferFromArrayBuffer(buffer) : buffer;
const mime = await core_js_1.default.fromBuffer(actualBuffer);
if (!mime || !mime.mime) {
throw new Error("Could not find MIME for Buffer");
}
const format = formats.find((format) => format.mime === mime.mime);
if (!format || !format.decode) {
throw new Error(`Mime type ${mime.mime} does not support decoding`);
}
const image = new CustomJimp(await format.decode(actualBuffer, options?.[format.mime]));
image.mime = mime.mime;
(0, image_bitmap_js_1.attemptExifRotate)(image, actualBuffer);
return image;
}
/**
* Nicely format Jimp object when sent to the console e.g. console.log(image)
* @returns Pretty printed jimp object
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* console.log(image);
* ```
*/
inspect() {
return ("<Jimp " +
(this.bitmap === emptyBitmap
? "pending..."
: this.bitmap.width + "x" + this.bitmap.height) +
">");
}
/**
* Nicely format Jimp object when converted to a string
* @returns pretty printed
*/
toString() {
return "[object Jimp]";
}
/** Get the width of the image */
get width() {
return this.bitmap.width;
}
/** Get the height of the image */
get height() {
return this.bitmap.height;
}
/**
* 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({ width: 3, height: 3, color: 0xffffffff });
*
* await image.write("test/output.jpeg", {
* quality: 50,
* });
* ```
*/
async getBuffer(mime, options) {
const format = this.formats.find((format) => format.mime === mime);
if (!format || !format.encode) {
throw new Error(`Unsupported MIME type: ${mime}`);
}
let outputImage;
if (format.hasAlpha) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
outputImage = this;
}
else {
outputImage = new CustomJimp({
width: this.bitmap.width,
height: this.bitmap.height,
color: this.background,
});
(0, composite_js_1.composite)(outputImage, this);
}
return format.encode(outputImage.bitmap, options);
}
/**
* Converts the image to a base 64 string
*
* @param mime The mime type to export to
* @param options The options to use when exporting
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = Jimp.fromBuffer(Buffer.from([
* 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
* 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
* 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
* ]));
*
* const base64 = image.getBase64("image/jpeg", {
* quality: 50,
* });
* ```
*/
async getBase64(mime, options) {
const data = await this.getBuffer(mime, options);
return "data:" + mime + ";base64," + data.toString("base64");
}
/**
* Write the image to a file
* @param path the path to write the image to
* @param options the options to use when writing the image
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = Jimp.fromBuffer(Buffer.from([
* 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
* 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
* 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
* ]));
*
* await image.write("test/output.png");
* ```
*/
async write(path, options) {
const mimeType = lite_js_1.default.getType(path);
await (0, file_ops_1.writeFile)(path, await this.getBuffer(mimeType, options));
}
/**
* Clone the image into a new Jimp instance.
* @param this
* @returns A new Jimp instance
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = new Jimp({ width: 3, height: 3, color: 0xffffffff });
*
* const clone = image.clone();
* ```
*/
clone() {
return new CustomJimp({
...this.bitmap,
data: Buffer.from(this.bitmap.data),
});
}
/**
* Returns the offset of a pixel in the bitmap buffer
* @param x the x coordinate
* @param y the y coordinate
* @param edgeHandling (optional) define how to sum pixels from outside the border
* @returns the index of the pixel or -1 if not found
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = new Jimp({ width: 3, height: 3, color: 0xffffffff });
*
* image.getPixelIndex(1, 1); // 2
* ```
*/
getPixelIndex(x, y, edgeHandling) {
let xi;
let yi;
if (!edgeHandling) {
edgeHandling = types_1.Edge.EXTEND;
}
if (typeof x !== "number" || typeof y !== "number") {
throw new Error("x and y must be numbers");
}
// round input
x = Math.round(x);
y = Math.round(y);
xi = x;
yi = y;
if (edgeHandling === types_1.Edge.EXTEND) {
if (x < 0)
xi = 0;
if (x >= this.bitmap.width)
xi = this.bitmap.width - 1;
if (y < 0)
yi = 0;
if (y >= this.bitmap.height)
yi = this.bitmap.height - 1;
}
if (edgeHandling === types_1.Edge.WRAP) {
if (x < 0) {
xi = this.bitmap.width + x;
}
if (x >= this.bitmap.width) {
xi = x % this.bitmap.width;
}
if (y < 0) {
yi = this.bitmap.height + y;
}
if (y >= this.bitmap.height) {
yi = y % this.bitmap.height;
}
}
let i = (this.bitmap.width * yi + xi) << 2;
// if out of bounds index is -1
if (xi < 0 || xi >= this.bitmap.width) {
i = -1;
}
if (yi < 0 || yi >= this.bitmap.height) {
i = -1;
}
return i;
}
/**
* Returns the hex color value of a pixel
* @param x the x coordinate
* @param y the y coordinate
* @returns the color of the pixel
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = new Jimp({ width: 3, height: 3, color: 0xffffffff });
*
* image.getPixelColor(1, 1); // 0xffffffff
* ```
*/
getPixelColor(x, y) {
if (typeof x !== "number" || typeof y !== "number") {
throw new Error("x and y must be numbers");
}
const idx = this.getPixelIndex(x, y);
return this.bitmap.data.readUInt32BE(idx);
}
/**
* Sets the hex colour value of a pixel
*
* @param hex color to set
* @param x the x coordinate
* @param y the y coordinate
*
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = new Jimp({ width: 3, height: 3, color: 0xffffffff });
*
* image.setPixelColor(0xff0000ff, 0, 0);
* ```
*/
setPixelColor(hex, x, y) {
if (typeof hex !== "number" ||
typeof x !== "number" ||
typeof y !== "number") {
throw new Error("hex, x and y must be numbers");
}
const idx = this.getPixelIndex(x, y);
this.bitmap.data.writeUInt32BE(hex, idx);
return this;
}
/**
* Determine if the image contains opaque pixels.
*
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = new Jimp({ width: 3, height: 3, color: 0xffffffaa });
* const image2 = new Jimp({ width: 3, height: 3, color: 0xff0000ff });
*
* image.hasAlpha(); // false
* image2.hasAlpha(); // true
* ```
*/
hasAlpha() {
const { width, height, data } = this.bitmap;
const byteLen = (width * height) << 2;
for (let idx = 3; idx < byteLen; idx += 4) {
if (data[idx] !== 0xff) {
return true;
}
}
return false;
}
/**
* Composites a source image over to this image respecting alpha channels
* @param src the source Jimp instance
* @param x the x position to blit the image
* @param y the y position to blit the image
* @param options determine what mode to use
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = new Jimp({ width: 10, height: 10, color: 0xffffffff });
* const image2 = new Jimp({ width: 3, height: 3, color: 0xff0000ff });
*
* image.composite(image2, 3, 3);
* ```
*/
composite(src, x = 0, y = 0, options = {}) {
return (0, composite_js_1.composite)(this, src, x, y, options);
}
scan(x, y, w, h, f) {
return (0, utils_1.scan)(this, x, y, w, h, f);
}
/**
* Iterate scan through a region of the bitmap
* @param x the x coordinate to begin the scan at
* @param y the y coordinate to begin the scan at
* @param w the width of the scan region
* @param h the height of the scan region
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = new Jimp({ width: 3, height: 3, color: 0xffffffff });
*
* for (const { x, y, idx, image } of j.scanIterator()) {
* // do something with the pixel
* }
* ```
*/
scanIterator(x = 0, y = 0, w = this.bitmap.width, h = this.bitmap.height) {
if (typeof x !== "number" || typeof y !== "number") {
throw new Error("x and y must be numbers");
}
if (typeof w !== "number" || typeof h !== "number") {
throw new Error("w and h must be numbers");
}
return (0, utils_1.scanIterator)(this, x, y, w, h);
}
};
return CustomJimp;
}
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AA+HA,gCAyoBC;AAxwBD,uCAA8D;AAC9D,uCAAgE;AAChE,gEAAyC;AACzC,6CAAiC;AACjC,6CAAiE;AACjE,2DAAgC;AAEhC,uDAAiD;AAEjD,6DAA4D;AAE5D,MAAM,WAAW,GAAW;IAC1B,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACrB,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;CACV,CAAC;AAEF;;GAEG;AACH,SAAS,qBAAqB,CAAC,WAAwB;IACrD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IACpD,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAEzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;QACvC,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC;IACvB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,2DAA6D;AAApD,qHAAA,kBAAkB,OAAA;AAC3B,qDAAiD;AAAxC,yGAAA,SAAS,OAAA;AAClB,uDAAqC;AA2FrC;;GAEG;AACH,SAAgB,UAAU,CAGxB,EACA,OAAO,EAAE,UAAU,EACnB,OAAO,EA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0 +1,3 @@
{
"type": "commonjs"
}
+70
View File
@@ -0,0 +1,70 @@
import { RGBAColor } from "@jimp/types";
export declare function srcOver(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function dstOver(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function multiply(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function add(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function screen(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function overlay(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function darken(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function lighten(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function hardLight(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function difference(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function exclusion(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare const names: readonly [typeof srcOver, typeof dstOver, typeof multiply, typeof add, typeof screen, typeof overlay, typeof darken, typeof lighten, typeof hardLight, typeof difference, typeof exclusion];
export type CompositeMode = (typeof names)[number];
//# sourceMappingURL=composite-modes.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"composite-modes.d.ts","sourceRoot":"","sources":["../../../src/utils/composite-modes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,wBAAgB,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,SAAI;;;;;EAU9D;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,SAAI;;;;;EAU9D;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,SAAI;;;;;EAkB/D;AAED,wBAAgB,GAAG,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,SAAI;;;;;EAkB1D;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,SAAI;;;;;EAoC7D;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,SAAI;;;;;EAgC9D;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,SAAI;;;;;EA8B7D;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,SAAI;;;;;EA8B9D;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,SAAI;;;;;EAgChE;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,SAAI;;;;;EAkBjE;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,SAAI;;;;;EAoChE;AAED,eAAO,MAAM,KAAK,6LAYR,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC"}
+236
View File
@@ -0,0 +1,236 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.names = void 0;
exports.srcOver = srcOver;
exports.dstOver = dstOver;
exports.multiply = multiply;
exports.add = add;
exports.screen = screen;
exports.overlay = overlay;
exports.darken = darken;
exports.lighten = lighten;
exports.hardLight = hardLight;
exports.difference = difference;
exports.exclusion = exclusion;
function srcOver(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const r = (src.r * src.a + dst.r * dst.a * (1 - src.a)) / a;
const g = (src.g * src.a + dst.g * dst.a * (1 - src.a)) / a;
const b = (src.b * src.a + dst.b * dst.a * (1 - src.a)) / a;
return { r, g, b, a };
}
function dstOver(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const r = (dst.r * dst.a + src.r * src.a * (1 - dst.a)) / a;
const g = (dst.g * dst.a + src.g * src.a * (1 - dst.a)) / a;
const b = (dst.b * dst.a + src.b * src.a * (1 - dst.a)) / a;
return { r, g, b, a };
}
function multiply(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (sra * dra + sra * (1 - dst.a) + dra * (1 - src.a)) / a;
const g = (sga * dga + sga * (1 - dst.a) + dga * (1 - src.a)) / a;
const b = (sba * dba + sba * (1 - dst.a) + dba * (1 - src.a)) / a;
return { r, g, b, a };
}
function add(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (sra + dra) / a;
const g = (sga + dga) / a;
const b = (sba + dba) / a;
return { r, g, b, a };
}
function screen(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (sra * dst.a +
dra * src.a -
sra * dra +
sra * (1 - dst.a) +
dra * (1 - src.a)) /
a;
const g = (sga * dst.a +
dga * src.a -
sga * dga +
sga * (1 - dst.a) +
dga * (1 - src.a)) /
a;
const b = (sba * dst.a +
dba * src.a -
sba * dba +
sba * (1 - dst.a) +
dba * (1 - src.a)) /
a;
return { r, g, b, a };
}
function overlay(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (2 * dra <= dst.a
? 2 * sra * dra + sra * (1 - dst.a) + dra * (1 - src.a)
: sra * (1 + dst.a) + dra * (1 + src.a) - 2 * dra * sra - dst.a * src.a) /
a;
const g = (2 * dga <= dst.a
? 2 * sga * dga + sga * (1 - dst.a) + dga * (1 - src.a)
: sga * (1 + dst.a) + dga * (1 + src.a) - 2 * dga * sga - dst.a * src.a) /
a;
const b = (2 * dba <= dst.a
? 2 * sba * dba + sba * (1 - dst.a) + dba * (1 - src.a)
: sba * (1 + dst.a) + dba * (1 + src.a) - 2 * dba * sba - dst.a * src.a) /
a;
return { r, g, b, a };
}
function darken(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (Math.min(sra * dst.a, dra * src.a) +
sra * (1 - dst.a) +
dra * (1 - src.a)) /
a;
const g = (Math.min(sga * dst.a, dga * src.a) +
sga * (1 - dst.a) +
dga * (1 - src.a)) /
a;
const b = (Math.min(sba * dst.a, dba * src.a) +
sba * (1 - dst.a) +
dba * (1 - src.a)) /
a;
return { r, g, b, a };
}
function lighten(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (Math.max(sra * dst.a, dra * src.a) +
sra * (1 - dst.a) +
dra * (1 - src.a)) /
a;
const g = (Math.max(sga * dst.a, dga * src.a) +
sga * (1 - dst.a) +
dga * (1 - src.a)) /
a;
const b = (Math.max(sba * dst.a, dba * src.a) +
sba * (1 - dst.a) +
dba * (1 - src.a)) /
a;
return { r, g, b, a };
}
function hardLight(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (2 * sra <= src.a
? 2 * sra * dra + sra * (1 - dst.a) + dra * (1 - src.a)
: sra * (1 + dst.a) + dra * (1 + src.a) - 2 * dra * sra - dst.a * src.a) /
a;
const g = (2 * sga <= src.a
? 2 * sga * dga + sga * (1 - dst.a) + dga * (1 - src.a)
: sga * (1 + dst.a) + dga * (1 + src.a) - 2 * dga * sga - dst.a * src.a) /
a;
const b = (2 * sba <= src.a
? 2 * sba * dba + sba * (1 - dst.a) + dba * (1 - src.a)
: sba * (1 + dst.a) + dba * (1 + src.a) - 2 * dba * sba - dst.a * src.a) /
a;
return { r, g, b, a };
}
function difference(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (sra + dra - 2 * Math.min(sra * dst.a, dra * src.a)) / a;
const g = (sga + dga - 2 * Math.min(sga * dst.a, dga * src.a)) / a;
const b = (sba + dba - 2 * Math.min(sba * dst.a, dba * src.a)) / a;
return { r, g, b, a };
}
function exclusion(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (sra * dst.a +
dra * src.a -
2 * sra * dra +
sra * (1 - dst.a) +
dra * (1 - src.a)) /
a;
const g = (sga * dst.a +
dga * src.a -
2 * sga * dga +
sga * (1 - dst.a) +
dga * (1 - src.a)) /
a;
const b = (sba * dst.a +
dba * src.a -
2 * sba * dba +
sba * (1 - dst.a) +
dba * (1 - src.a)) /
a;
return { r, g, b, a };
}
exports.names = [
srcOver,
dstOver,
multiply,
add,
screen,
overlay,
darken,
lighten,
hardLight,
difference,
exclusion,
];
//# sourceMappingURL=composite-modes.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"composite-modes.js","sourceRoot":"","sources":["../../../src/utils/composite-modes.ts"],"names":[],"mappings":";;;AAEA,0BAUC;AAED,0BAUC;AAED,4BAkBC;AAED,kBAkBC;AAED,wBAoCC;AAED,0BAgCC;AAED,wBA8BC;AAED,0BA8BC;AAED,8BAgCC;AAED,gCAkBC;AAED,8BAoCC;AAlSD,SAAgB,OAAO,CAAC,GAAc,EAAE,GAAc,EAAE,GAAG,GAAG,CAAC;IAC7D,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC;IAEb,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IAExC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC5D,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CA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CAAC,CAAC,CAAC;QACpB,CAAC,CAAC;IAEJ,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AACxB,CAAC;AAED,SAAgB,OAAO,CLine truncated
+8
View File
@@ -0,0 +1,8 @@
import { JimpClass } from "@jimp/types";
import { BlendMode } from "./constants.js";
export declare function composite<I extends JimpClass>(baseImage: I, src: I, x?: number, y?: number, options?: {
mode?: BlendMode;
opacitySource?: number;
opacityDest?: number;
}): I;
//# sourceMappingURL=composite.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"composite.d.ts","sourceRoot":"","sources":["../../../src/utils/composite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,SAAS,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI3C,wBAAgB,SAAS,CAAC,CAAC,SAAS,SAAS,EAC3C,SAAS,EAAE,CAAC,EACZ,GAAG,EAAE,CAAC,EACN,CAAC,SAAI,EACL,CAAC,SAAI,EACL,OAAO,GAAE;IACP,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACjB,KAqEP"}
+82
View File
@@ -0,0 +1,82 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.composite = composite;
const types_1 = require("@jimp/types");
const constants_js_1 = require("./constants.js");
const compositeModes = __importStar(require("./composite-modes.js"));
const utils_1 = require("@jimp/utils");
function composite(baseImage, src, x = 0, y = 0, options = {}) {
if (!(src instanceof baseImage.constructor)) {
throw new Error("The source must be a Jimp image");
}
if (typeof x !== "number" || typeof y !== "number") {
throw new Error("x and y must be numbers");
}
const { mode = constants_js_1.BlendMode.SRC_OVER } = options;
let { opacitySource = 1.0, opacityDest = 1.0 } = options;
if (typeof opacitySource !== "number" ||
opacitySource < 0 ||
opacitySource > 1) {
opacitySource = 1.0;
}
if (typeof opacityDest !== "number" || opacityDest < 0 || opacityDest > 1) {
opacityDest = 1.0;
}
const blendmode = compositeModes[mode];
// round input
x = Math.round(x);
y = Math.round(y);
if (opacityDest !== 1.0) {
baseImage.scan((_, __, idx) => {
const v = baseImage.bitmap.data[idx + 3] * opacityDest;
baseImage.bitmap.data[idx + 3] = v;
});
}
src.scan((sx, sy, idx) => {
const dstIdx = baseImage.getPixelIndex(x + sx, y + sy, types_1.Edge.CROP);
if (dstIdx === -1) {
// Skip target pixels outside of dst
return;
}
const blended = blendmode({
r: src.bitmap.data[idx + 0] / 255,
g: src.bitmap.data[idx + 1] / 255,
b: src.bitmap.data[idx + 2] / 255,
a: src.bitmap.data[idx + 3] / 255,
}, {
r: baseImage.bitmap.data[dstIdx + 0] / 255,
g: baseImage.bitmap.data[dstIdx + 1] / 255,
b: baseImage.bitmap.data[dstIdx + 2] / 255,
a: baseImage.bitmap.data[dstIdx + 3] / 255,
}, opacitySource);
baseImage.bitmap.data[dstIdx + 0] = (0, utils_1.limit255)(blended.r * 255);
baseImage.bitmap.data[dstIdx + 1] = (0, utils_1.limit255)(blended.g * 255);
baseImage.bitmap.data[dstIdx + 2] = (0, utils_1.limit255)(blended.b * 255);
baseImage.bitmap.data[dstIdx + 3] = (0, utils_1.limit255)(blended.a * 255);
});
return baseImage;
}
//# sourceMappingURL=composite.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"composite.js","sourceRoot":"","sources":["../../../src/utils/composite.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAMA,8BA8EC;AApFD,uCAA8C;AAE9C,iDAA2C;AAC3C,qEAAuD;AACvD,uCAAuC;AAEvC,SAAgB,SAAS,CACvB,SAAY,EACZ,GAAM,EACN,CAAC,GAAG,CAAC,EACL,CAAC,GAAG,CAAC,EACL,UAII,EAAE;IAEN,IAAI,CAAC,CAAC,GAAG,YAAY,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IAED,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QACnD,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAED,MAAM,EAAE,IAAI,GAAG,wBAAS,CAAC,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC9C,IAAI,EAAE,aAAa,GAAG,GAAG,EAAE,WAAW,GAAG,GAAG,EAAE,GAAG,OAAO,CAAC;IAEzD,IACE,OAAO,aAAa,KAAK,QAAQ;QACjC,aAAa,GAAG,CAAC;QACjB,aAAa,GAAG,CAAC,EACjB,CAAC;QACD,aAAa,GAAG,GAAG,CAAC;IACtB,CAAC;IAED,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,GAAG,CAAC,IAAI,WAAW,GAAG,CAAC,EAAE,CAAC;QAC1E,WAAW,GAAG,GAAG,CAAC;IACpB,CAAC;IAED,MAAM,SAAS,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IAEvC,cAAc;IACd,CAAC,GA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YAC3C,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAE,GAAG,GAAG;YAC3C,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAE,GAAG,GAAG;YAC3C,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAE,GAAG,GAAG;SAC5C,EACD,aAAa,CACd,CAAC;QAEF,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAA,gBAAQ,EAAC,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;QAC9D,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAA,gBAAQ,EAAC,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;QAC9D,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAA,gBAAQ,EAAC,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;QAC9D,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAA,gBAAQ,EAAC,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC"}
+85
View File
@@ -0,0 +1,85 @@
export declare enum HorizontalAlign {
LEFT = 1,
CENTER = 2,
RIGHT = 4
}
export declare enum VerticalAlign {
TOP = 8,
MIDDLE = 16,
BOTTOM = 32
}
/**
* How to blend two images together
*/
export declare enum BlendMode {
/**
* Composite the source image over the destination image.
* This is the default value. It represents the most intuitive case, where shapes are painted on top of what is below, with transparent areas showing the destination layer.
*/
SRC_OVER = "srcOver",
/** Composite the source image under the destination image. */
DST_OVER = "dstOver",
/**
* Multiply the color components of the source and destination images.
* This can only result in the same or darker colors (multiplying by white, 1.0, results in no change; multiplying by black, 0.0, results in black).
* When compositing two opaque images, this has similar effect to overlapping two transparencies on a projector.
*
* This mode is useful for coloring shadows.
*/
MULTIPLY = "multiply",
/**
* The Add mode adds the color information of the base layers and the blending layer.
* In digital terms, adding color increases the brightness.
*/
ADD = "add",
/**
* Multiply the inverse of the components of the source and destination images, and inverse the result.
* Inverting the components means that a fully saturated channel (opaque white) is treated as the value 0.0, and values normally treated as 0.0 (black, transparent) are treated as 1.0.
* This is essentially the same as modulate blend mode, but with the values of the colors inverted before the multiplication and the result being inverted back before rendering.
* This can only result in the same or lighter colors (multiplying by black, 1.0, results in no change; multiplying by white, 0.0, results in white). Similarly, in the alpha channel, it can only result in more opaque colors.
* This has similar effect to two projectors displaying their images on the same screen simultaneously.
*/
SCREEN = "screen",
/**
* Multiply the components of the source and destination images after adjusting them to favor the destination.
* Specifically, if the destination value is smaller, this multiplies it with the source value, whereas is the source value is smaller, it multiplies the inverse of the source value with the inverse of the destination value, then inverts the result.
* Inverting the components means that a fully saturated channel (opaque white) is treated as the value 0.0, and values normally treated as 0.0 (black, transparent) are treated as 1.0.
*
* The Overlay mode behaves like Screen mode in bright areas, and like Multiply mode in darker areas.
* With this mode, the bright areas will look brighter and the dark areas will look darker.
*/
OVERLAY = "overlay",
/**
* Composite the source and destination image by choosing the lowest value from each color channel.
* The opacity of the output image is computed in the same way as for srcOver.
*/
DARKEN = "darken",
/**
* Composite the source and destination image by choosing the highest value from each color channel.
* The opacity of the output image is computed in the same way as for srcOver.
*/
LIGHTEN = "lighten",
/**
* Multiply the components of the source and destination images after adjusting them to favor the source.
* Specifically, if the source value is smaller, this multiplies it with the destination value, whereas is the destination value is smaller, it multiplies the inverse of the destination value with the inverse of the source value, then inverts the result.
* Inverting the components means that a fully saturated channel (opaque white) is treated as the value 0.0, and values normally treated as 0.0 (black, transparent) are treated as 1.0.
*
* The effect of the Hard light mode depends on the density of the superimposed color. Using bright colors on the blending layer will create a brighter effect like the Screen modes, while dark colors will create darker colors like the Multiply mode.
*/
HARD_LIGHT = "hardLight",
/**
* Subtract the smaller value from the bigger value for each channel.
* Compositing black has no effect; compositing white inverts the colors of the other image.
* The opacity of the output image is computed in the same way as for srcOver.
* The effect is similar to exclusion but harsher.
*/
DIFFERENCE = "difference",
/**
* Subtract double the product of the two images from the sum of the two images.
* Compositing black has no effect; compositing white inverts the colors of the other image.
* The opacity of the output image is computed in the same way as for srcOver.
* The effect is similar to difference but softer.
*/
EXCLUSION = "exclusion"
}
//# sourceMappingURL=constants.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/utils/constants.ts"],"names":[],"mappings":"AACA,oBAAY,eAAe;IACzB,IAAI,IAAI;IACR,MAAM,IAAI;IACV,KAAK,IAAI;CACV;AAGD,oBAAY,aAAa;IACvB,GAAG,IAAI;IACP,MAAM,KAAK;IACX,MAAM,KAAK;CACZ;AAED;;GAEG;AACH,oBAAY,SAAS;IACnB;;;OAGG;IACH,QAAQ,YAAY;IACpB,8DAA8D;IAC9D,QAAQ,YAAY;IACpB;;;;;;OAMG;IACH,QAAQ,aAAa;IACrB;;;OAGG;IACH,GAAG,QAAQ;IACX;;;;;;OAMG;IACH,MAAM,WAAW;IACjB;;;;;;;OAOG;IACH,OAAO,YAAY;IACnB;;;OAGG;IACH,MAAM,WAAW;IACjB;;;OAGG;IACH,OAAO,YAAY;IACnB;;;;;;OAMG;IACH,UAAU,cAAc;IACxB;;;;;OAKG;IACH,UAAU,eAAe;IACzB;;;;;OAKG;IACH,SAAS,cAAc;CACxB"}
+93
View File
@@ -0,0 +1,93 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BlendMode = exports.VerticalAlign = exports.HorizontalAlign = void 0;
/* Horizontal align modes for cover, contain, bit masks */
var HorizontalAlign;
(function (HorizontalAlign) {
HorizontalAlign[HorizontalAlign["LEFT"] = 1] = "LEFT";
HorizontalAlign[HorizontalAlign["CENTER"] = 2] = "CENTER";
HorizontalAlign[HorizontalAlign["RIGHT"] = 4] = "RIGHT";
})(HorizontalAlign || (exports.HorizontalAlign = HorizontalAlign = {}));
/* Vertical align modes for cover, contain, bit masks */
var VerticalAlign;
(function (VerticalAlign) {
VerticalAlign[VerticalAlign["TOP"] = 8] = "TOP";
VerticalAlign[VerticalAlign["MIDDLE"] = 16] = "MIDDLE";
VerticalAlign[VerticalAlign["BOTTOM"] = 32] = "BOTTOM";
})(VerticalAlign || (exports.VerticalAlign = VerticalAlign = {}));
/**
* How to blend two images together
*/
var BlendMode;
(function (BlendMode) {
/**
* Composite the source image over the destination image.
* This is the default value. It represents the most intuitive case, where shapes are painted on top of what is below, with transparent areas showing the destination layer.
*/
BlendMode["SRC_OVER"] = "srcOver";
/** Composite the source image under the destination image. */
BlendMode["DST_OVER"] = "dstOver";
/**
* Multiply the color components of the source and destination images.
* This can only result in the same or darker colors (multiplying by white, 1.0, results in no change; multiplying by black, 0.0, results in black).
* When compositing two opaque images, this has similar effect to overlapping two transparencies on a projector.
*
* This mode is useful for coloring shadows.
*/
BlendMode["MULTIPLY"] = "multiply";
/**
* The Add mode adds the color information of the base layers and the blending layer.
* In digital terms, adding color increases the brightness.
*/
BlendMode["ADD"] = "add";
/**
* Multiply the inverse of the components of the source and destination images, and inverse the result.
* Inverting the components means that a fully saturated channel (opaque white) is treated as the value 0.0, and values normally treated as 0.0 (black, transparent) are treated as 1.0.
* This is essentially the same as modulate blend mode, but with the values of the colors inverted before the multiplication and the result being inverted back before rendering.
* This can only result in the same or lighter colors (multiplying by black, 1.0, results in no change; multiplying by white, 0.0, results in white). Similarly, in the alpha channel, it can only result in more opaque colors.
* This has similar effect to two projectors displaying their images on the same screen simultaneously.
*/
BlendMode["SCREEN"] = "screen";
/**
* Multiply the components of the source and destination images after adjusting them to favor the destination.
* Specifically, if the destination value is smaller, this multiplies it with the source value, whereas is the source value is smaller, it multiplies the inverse of the source value with the inverse of the destination value, then inverts the result.
* Inverting the components means that a fully saturated channel (opaque white) is treated as the value 0.0, and values normally treated as 0.0 (black, transparent) are treated as 1.0.
*
* The Overlay mode behaves like Screen mode in bright areas, and like Multiply mode in darker areas.
* With this mode, the bright areas will look brighter and the dark areas will look darker.
*/
BlendMode["OVERLAY"] = "overlay";
/**
* Composite the source and destination image by choosing the lowest value from each color channel.
* The opacity of the output image is computed in the same way as for srcOver.
*/
BlendMode["DARKEN"] = "darken";
/**
* Composite the source and destination image by choosing the highest value from each color channel.
* The opacity of the output image is computed in the same way as for srcOver.
*/
BlendMode["LIGHTEN"] = "lighten";
/**
* Multiply the components of the source and destination images after adjusting them to favor the source.
* Specifically, if the source value is smaller, this multiplies it with the destination value, whereas is the destination value is smaller, it multiplies the inverse of the destination value with the inverse of the source value, then inverts the result.
* Inverting the components means that a fully saturated channel (opaque white) is treated as the value 0.0, and values normally treated as 0.0 (black, transparent) are treated as 1.0.
*
* The effect of the Hard light mode depends on the density of the superimposed color. Using bright colors on the blending layer will create a brighter effect like the Screen modes, while dark colors will create darker colors like the Multiply mode.
*/
BlendMode["HARD_LIGHT"] = "hardLight";
/**
* Subtract the smaller value from the bigger value for each channel.
* Compositing black has no effect; compositing white inverts the colors of the other image.
* The opacity of the output image is computed in the same way as for srcOver.
* The effect is similar to exclusion but harsher.
*/
BlendMode["DIFFERENCE"] = "difference";
/**
* Subtract double the product of the two images from the sum of the two images.
* Compositing black has no effect; compositing white inverts the colors of the other image.
* The opacity of the output image is computed in the same way as for srcOver.
* The effect is similar to difference but softer.
*/
BlendMode["EXCLUSION"] = "exclusion";
})(BlendMode || (exports.BlendMode = BlendMode = {}));
//# sourceMappingURL=constants.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/utils/constants.ts"],"names":[],"mappings":";;;AAAA,0DAA0D;AAC1D,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,qDAAQ,CAAA;IACR,yDAAU,CAAA;IACV,uDAAS,CAAA;AACX,CAAC,EAJW,eAAe,+BAAf,eAAe,QAI1B;AAED,wDAAwD;AACxD,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,+CAAO,CAAA;IACP,sDAAW,CAAA;IACX,sDAAW,CAAA;AACb,CAAC,EAJW,aAAa,6BAAb,aAAa,QAIxB;AAED;;GAEG;AACH,IAAY,SAsEX;AAtED,WAAY,SAAS;IACnB;;;OAGG;IACH,iCAAoB,CAAA;IACpB,8DAA8D;IAC9D,iCAAoB,CAAA;IACpB;;;;;;OAMG;IACH,kCAAqB,CAAA;IACrB;;;OAGG;IACH,wBAAW,CAAA;IACX;;;;;;OAMG;IACH,8BAAiB,CAAA;IACjB;;;;;;;OAOG;IACH,gCAAmB,CAAA;IACnB;;;OAGG;IACH,8BAAiB,CAAA;IACjB;;;OAGG;IACH,gCAAmB,CAAA;IACnB;;;;;;OAMG;IACH,qCAAwB,CAAA;IACxB;;;;;OAKG;IACH,sCAAyB,CAAA;IACzB;;;;;OAKG;IACH,oCAAuB,CAAA;AACzB,CAAC,EAtEW,SAAS,yBAAT,SAAS,QAsEpB"}
+11
View File
@@ -0,0 +1,11 @@
import { JimpClass } from "@jimp/types";
/**
* Obtains image orientation from EXIF metadata.
*
* @param img a Jimp image object
* @returns a number 1-8 representing EXIF orientation,
* in particular 1 if orientation tag is missing
*/
export declare function getExifOrientation<I extends JimpClass>(img: I): number;
export declare function attemptExifRotate<I extends JimpClass>(image: I, buffer: Buffer): Promise<void>;
//# sourceMappingURL=image-bitmap.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"image-bitmap.d.ts","sourceRoot":"","sources":["../../../src/utils/image-bitmap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,SAAS,EAAE,GAAG,EAAE,CAAC,UAG7D;AA+HD,wBAAsB,iBAAiB,CAAC,CAAC,SAAS,SAAS,EACzD,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,MAAM,iBAUf"}
+129
View File
@@ -0,0 +1,129 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getExifOrientation = getExifOrientation;
exports.attemptExifRotate = attemptExifRotate;
const exif_parser_1 = __importDefault(require("exif-parser"));
/**
* Obtains image orientation from EXIF metadata.
*
* @param img a Jimp image object
* @returns a number 1-8 representing EXIF orientation,
* in particular 1 if orientation tag is missing
*/
function getExifOrientation(img) {
const _exif = img._exif;
return (_exif && _exif.tags && _exif.tags.Orientation) || 1;
}
/**
* Returns a function which translates EXIF-rotated coordinates into
* non-rotated ones.
*
* Transformation reference: http://sylvana.net/jpegcrop/exif_orientation.html.
*
* @param img a Jimp image object
* @returns transformation function for transformBitmap().
*/
function getExifOrientationTransformation(img) {
const w = img.bitmap.width;
const h = img.bitmap.height;
switch (getExifOrientation(img)) {
case 1: // Horizontal (normal)
// does not need to be supported here
return null;
case 2: // Mirror horizontal
return function (x, y) {
return [w - x - 1, y];
};
case 3: // Rotate 180
return function (x, y) {
return [w - x - 1, h - y - 1];
};
case 4: // Mirror vertical
return function (x, y) {
return [x, h - y - 1];
};
case 5: // Mirror horizontal and rotate 270 CW
return function (x, y) {
return [y, x];
};
case 6: // Rotate 90 CW
return function (x, y) {
return [y, h - x - 1];
};
case 7: // Mirror horizontal and rotate 90 CW
return function (x, y) {
return [w - y - 1, h - x - 1];
};
case 8: // Rotate 270 CW
return function (x, y) {
return [w - y - 1, x];
};
default:
return null;
}
}
/**
* Transforms bitmap in place (moves pixels around) according to given
* transformation function.
*
* @param img a Jimp image object, which bitmap is supposed to
* be transformed
* @param width bitmap width after the transformation
* @param height bitmap height after the transformation
* @param transformation transformation function which defines pixel
* mapping between new and source bitmap. It takes a pair of coordinates
* in the target, and returns a respective pair of coordinates in
* the source bitmap, i.e. has following form:
* `function(new_x, new_y) { return [src_x, src_y] }`.
*/
function transformBitmap(img, width, height, transformation) {
// Underscore-prefixed values are related to the source bitmap
// Their counterparts with no prefix are related to the target bitmap
const _data = img.bitmap.data;
const _width = img.bitmap.width;
const data = Buffer.alloc(_data.length);
for (let x = 0; x < width; x++) {
for (let y = 0; y < height; y++) {
const [_x, _y] = transformation(x, y);
const idx = (width * y + x) << 2;
const _idx = (_width * _y + _x) << 2;
const pixel = _data.readUInt32BE(_idx);
data.writeUInt32BE(pixel, idx);
}
}
img.bitmap.data = data;
img.bitmap.width = width;
img.bitmap.height = height;
// @ts-expect-error Accessing private property
img._exif.tags.Orientation = 1;
}
/**
* Automagically rotates an image based on its EXIF data (if present).
* @param img a Jimp image object
*/
function exifRotate(img) {
if (getExifOrientation(img) < 2) {
return;
}
const transformation = getExifOrientationTransformation(img);
const swapDimensions = getExifOrientation(img) > 4;
const newWidth = swapDimensions ? img.bitmap.height : img.bitmap.width;
const newHeight = swapDimensions ? img.bitmap.width : img.bitmap.height;
if (transformation) {
transformBitmap(img, newWidth, newHeight, transformation);
}
}
async function attemptExifRotate(image, buffer) {
try {
image._exif =
exif_parser_1.default.create(buffer).parse();
exifRotate(image); // EXIF data
}
catch {
// do nothing
}
}
//# sourceMappingURL=image-bitmap.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"image-bitmap.js","sourceRoot":"","sources":["../../../src/utils/image-bitmap.ts"],"names":[],"mappings":";;;;;AAUA,gDAGC;AA+HD,8CAYC;AAxJD,8DAAmD;AAGnD;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAAsB,GAAM;IAC5D,MAAM,KAAK,GAAI,GAAsC,CAAC,KAAK,CAAC;IAC5D,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,gCAAgC,CAAsB,GAAM;IACnE,MAAM,CAAC,G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C,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;IAE3B,8CAA8C;IAC9C,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;AACjC,CAAC;AAED;;;GAGG;AACH,SAAS,UAAU,CAAsB,GAAM;IAC7C,IAAI,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAChC,OAAO;IACT,CAAC;IAED,MAAM,cAAc,GAAG,gCAAgC,CAAC,GAAG,CAAC,CAAC;IAC7D,MAAM,cAAc,GAAG,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAEnD,MAAM,QAAQ,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;IACvE,MAAM,SAAS,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;IAExE,IAAI,cAAc,EAAE,CAAC;QACnB,eAAe,CAAC,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC;AAEM,KAAK,UAAU,iBAAiB,CACrC,KAAQ,EACR,MAAc;IAEd,IAAI,CAAC;QACF,KAAwC,CAAC,KAAK;YAC7C,qBAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC;QAEpC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,aAAa;IACf,CAAC;AACH,CAAC"}
+2
View File
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=mime.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"mime.d.ts","sourceRoot":"","sources":["../../../src/utils/mime.ts"],"names":[],"mappings":""}
+30
View File
@@ -0,0 +1,30 @@
"use strict";
// const mimeTypes = {};
Object.defineProperty(exports, "__esModule", { value: true });
// const findType = (extension: string) =>
// Object.entries(mimeTypes).find((type) => type[1].includes(extension)) || [];
// export const addType = (mime: string, extensions: string[]) => {
// mimeTypes[mime] = extensions;
// };
// /**
// * Lookup a mime type based on extension
// * @param {string} path path to find extension for
// * @returns {string} mime found mime type
// */
// export const getType = (path: string) => {
// const pathParts = path.split("/").slice(-1);
// const extension = pathParts[pathParts.length - 1]?.split(".").pop();
// if (!extension) {
// return null;
// }
// const type = findType(extension);
// return type[0];
// };
// /**
// * Return file extension associated with a mime type
// * @param {string} type mime type to look up
// * @returns {string} extension file extension
// */
// export const getExtension = (type: string) =>
// (mimeTypes[type.toLowerCase()] || [])[0];
//# sourceMappingURL=mime.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"mime.js","sourceRoot":"","sources":["../../../src/utils/mime.ts"],"names":[],"mappings":";AAAA,wBAAwB;;AAExB,0CAA0C;AAC1C,iFAAiF;AAEjF,mEAAmE;AACnE,kCAAkC;AAClC,KAAK;AAEL,MAAM;AACN,2CAA2C;AAC3C,qDAAqD;AACrD,4CAA4C;AAC5C,MAAM;AACN,6CAA6C;AAC7C,iDAAiD;AACjD,yEAAyE;AAEzE,sBAAsB;AACtB,mBAAmB;AACnB,MAAM;AAEN,sCAAsC;AAEtC,oBAAoB;AACpB,KAAK;AAEL,MAAM;AACN,uDAAuD;AACvD,+CAA+C;AAC/C,gDAAgD;AAChD,MAAM;AACN,gDAAgD;AAChD,8CAA8C"}
+1904
View File
File diff suppressed because it is too large. Load diff
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAQ9D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAuBvC,OAAO,EAAE,kBAAkB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kBAED,gBAAgB,8CAChB,OAAO;QAST;;;;;;;;;;;;;;;;WAgBG;cAED,SAAS,SAAS,MAAM,EACxB,IAAI,6GACJ,OAAO;QAST;;;;;;;;;;;;WAYG;cACG,CAAC;QAOP;;;;;;;;;;;;;;WAcG;yBACc,MAAM,KAAK,MAAM,iBAAiB,IAAI;QAyDvD;;;;;;;;;;;;;WAaG;yBACc,MAAM,KAAK,MAAM;QASlC;;;;;;;;;;;;;;;WAeG;2BACgB,MAAM,KAAK,MAAM,KAAK,MAAM;QAe/C;;;;;;;;;;;;;WAaG;;QAcH;;;;;;;;;;;;;;;WAeG;kBACO,CAAC,wDAIA;YACP,IAAI,CAAC,EAAE,SAAS,CAAC;YACjB,aAAa,CAAC,EAAE,MAAM,CAAC;YACvB,WAAW,CAAC,EAAE,MAAM,CAAC;SACtB;QAKH;;;;;;;;;;;;;;;;;;WAkBG;gBACK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,GAAG;QAnBlD;;;;;;;;;;;;;;;;;;WAkBG;gBAGLine truncated
+506
View File
@@ -0,0 +1,506 @@
import { Edge } from "@jimp/types";
import { cssColorToHex, scan, scanIterator } from "@jimp/utils";
import fileType from "file-type/core.js";
import { to } from "await-to-js";
import { existsSync, readFile, writeFile } from "@jimp/file-ops";
import mime from "mime/lite.js";
import { composite } from "./utils/composite.js";
import { attemptExifRotate } from "./utils/image-bitmap.js";
const emptyBitmap = {
data: Buffer.alloc(0),
width: 0,
height: 0,
};
/**
* Prepare a Buffer object from the arrayBuffer.
*/
function bufferFromArrayBuffer(arrayBuffer) {
const buffer = Buffer.alloc(arrayBuffer.byteLength);
const view = new Uint8Array(arrayBuffer);
for (let i = 0; i < buffer.length; ++i) {
buffer[i] = view[i];
}
return buffer;
}
export { getExifOrientation } from "./utils/image-bitmap.js";
export { composite } from "./utils/composite.js";
export * from "./utils/constants.js";
/**
* Create a Jimp class that support the given image formats and methods
*/
export function createJimp({ plugins: pluginsArg, formats: formatsArg, } = {}) {
const plugins = pluginsArg || [];
const formats = (formatsArg || []).map((format) => format());
const CustomJimp = class Jimp {
/**
* The bitmap data of the image
*/
bitmap = emptyBitmap;
/** Default color to use for new pixels */
background = 0x00000000;
/** Formats that can be used with Jimp */
formats = [];
/** The original MIME type of the image */
mime;
constructor(options = emptyBitmap) {
// Add the formats
this.formats = formats;
if ("data" in options) {
this.bitmap = options;
}
else {
this.bitmap = {
data: Buffer.alloc(options.width * options.height * 4),
width: options.width,
height: options.height,
};
if (options.color) {
this.background =
typeof options.color === "string"
? cssColorToHex(options.color)
: options.color;
for (let i = 0; i < this.bitmap.data.length; i += 4) {
this.bitmap.data.writeUInt32BE(this.background, i);
}
}
}
// Add the plugins
for (const methods of plugins) {
for (const key in methods) {
this[key] = (...args) => {
const result = methods[key]?.(this, ...args);
if (typeof result === "object" && "bitmap" in result) {
this.bitmap = result.bitmap;
return this;
}
return result;
};
}
}
}
/**
* 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://upload.wikimedia.org/wikipedia/commons/0/01/Bot-Test.jpg");
* ```
*/
static async read(url, options) {
if (Buffer.isBuffer(url) || url instanceof ArrayBuffer) {
return this.fromBuffer(url);
}
if (existsSync(url)) {
return this.fromBuffer(await readFile(url));
}
const [fetchErr, response] = await to(fetch(url));
if (fetchErr) {
throw new Error(`Could not load Buffer from URL: ${url}`);
}
if (!response.ok) {
throw new Error(`HTTP Status ${response.status} for url ${url}`);
}
const [arrayBufferErr, data] = await to(response.arrayBuffer());
if (arrayBufferErr) {
throw new Error(`Could not load Buffer from ${url}`);
}
const buffer = bufferFromArrayBuffer(data);
return this.fromBuffer(buffer, options);
}
/**
* Create a Jimp instance from a bitmap.
* The difference between this and just using the constructor is that this will
* convert raw image data into the bitmap format that Jimp uses.
*
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = Jimp.fromBitmap({
* data: Buffer.from([
* 0xffffffff, 0xffffffff, 0xffffffff,
* 0xffffffff, 0xffffffff, 0xffffffff,
* 0xffffffff, 0xffffffff, 0xffffffff,
* ]),
* width: 3,
* height: 3,
* });
* ```
*/
static fromBitmap(bitmap) {
let data;
if (bitmap.data instanceof Buffer) {
data = Buffer.from(bitmap.data);
}
if (bitmap.data instanceof Uint8Array ||
bitmap.data instanceof Uint8ClampedArray) {
data = Buffer.from(bitmap.data.buffer);
}
if (Array.isArray(bitmap.data)) {
data = Buffer.concat(bitmap.data.map((hex) => Buffer.from(hex.toString(16).padStart(8, "0"), "hex")));
}
if (!data) {
throw new Error("data must be a Buffer");
}
if (typeof bitmap.height !== "number" ||
typeof bitmap.width !== "number") {
throw new Error("bitmap must have width and height");
}
return new CustomJimp({
height: bitmap.height,
width: bitmap.width,
data,
});
}
/**
* Parse a bitmap with the loaded image types.
*
* @param buffer Raw image data
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const buffer = await fs.readFile("test/image.png");
* const image = await Jimp.fromBuffer(buffer);
* ```
*/
static async fromBuffer(buffer, options) {
const actualBuffer = buffer instanceof ArrayBuffer ? bufferFromArrayBuffer(buffer) : buffer;
const mime = await fileType.fromBuffer(actualBuffer);
if (!mime || !mime.mime) {
throw new Error("Could not find MIME for Buffer");
}
const format = formats.find((format) => format.mime === mime.mime);
if (!format || !format.decode) {
throw new Error(`Mime type ${mime.mime} does not support decoding`);
}
const image = new CustomJimp(await format.decode(actualBuffer, options?.[format.mime]));
image.mime = mime.mime;
attemptExifRotate(image, actualBuffer);
return image;
}
/**
* Nicely format Jimp object when sent to the console e.g. console.log(image)
* @returns Pretty printed jimp object
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
*
* console.log(image);
* ```
*/
inspect() {
return ("<Jimp " +
(this.bitmap === emptyBitmap
? "pending..."
: this.bitmap.width + "x" + this.bitmap.height) +
">");
}
/**
* Nicely format Jimp object when converted to a string
* @returns pretty printed
*/
toString() {
return "[object Jimp]";
}
/** Get the width of the image */
get width() {
return this.bitmap.width;
}
/** Get the height of the image */
get height() {
return this.bitmap.height;
}
/**
* 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({ width: 3, height: 3, color: 0xffffffff });
*
* await image.write("test/output.jpeg", {
* quality: 50,
* });
* ```
*/
async getBuffer(mime, options) {
const format = this.formats.find((format) => format.mime === mime);
if (!format || !format.encode) {
throw new Error(`Unsupported MIME type: ${mime}`);
}
let outputImage;
if (format.hasAlpha) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
outputImage = this;
}
else {
outputImage = new CustomJimp({
width: this.bitmap.width,
height: this.bitmap.height,
color: this.background,
});
composite(outputImage, this);
}
return format.encode(outputImage.bitmap, options);
}
/**
* Converts the image to a base 64 string
*
* @param mime The mime type to export to
* @param options The options to use when exporting
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = Jimp.fromBuffer(Buffer.from([
* 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
* 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
* 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
* ]));
*
* const base64 = image.getBase64("image/jpeg", {
* quality: 50,
* });
* ```
*/
async getBase64(mime, options) {
const data = await this.getBuffer(mime, options);
return "data:" + mime + ";base64," + data.toString("base64");
}
/**
* Write the image to a file
* @param path the path to write the image to
* @param options the options to use when writing the image
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = Jimp.fromBuffer(Buffer.from([
* 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
* 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
* 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
* ]));
*
* await image.write("test/output.png");
* ```
*/
async write(path, options) {
const mimeType = mime.getType(path);
await writeFile(path, await this.getBuffer(mimeType, options));
}
/**
* Clone the image into a new Jimp instance.
* @param this
* @returns A new Jimp instance
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = new Jimp({ width: 3, height: 3, color: 0xffffffff });
*
* const clone = image.clone();
* ```
*/
clone() {
return new CustomJimp({
...this.bitmap,
data: Buffer.from(this.bitmap.data),
});
}
/**
* Returns the offset of a pixel in the bitmap buffer
* @param x the x coordinate
* @param y the y coordinate
* @param edgeHandling (optional) define how to sum pixels from outside the border
* @returns the index of the pixel or -1 if not found
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = new Jimp({ width: 3, height: 3, color: 0xffffffff });
*
* image.getPixelIndex(1, 1); // 2
* ```
*/
getPixelIndex(x, y, edgeHandling) {
let xi;
let yi;
if (!edgeHandling) {
edgeHandling = Edge.EXTEND;
}
if (typeof x !== "number" || typeof y !== "number") {
throw new Error("x and y must be numbers");
}
// round input
x = Math.round(x);
y = Math.round(y);
xi = x;
yi = y;
if (edgeHandling === Edge.EXTEND) {
if (x < 0)
xi = 0;
if (x >= this.bitmap.width)
xi = this.bitmap.width - 1;
if (y < 0)
yi = 0;
if (y >= this.bitmap.height)
yi = this.bitmap.height - 1;
}
if (edgeHandling === Edge.WRAP) {
if (x < 0) {
xi = this.bitmap.width + x;
}
if (x >= this.bitmap.width) {
xi = x % this.bitmap.width;
}
if (y < 0) {
yi = this.bitmap.height + y;
}
if (y >= this.bitmap.height) {
yi = y % this.bitmap.height;
}
}
let i = (this.bitmap.width * yi + xi) << 2;
// if out of bounds index is -1
if (xi < 0 || xi >= this.bitmap.width) {
i = -1;
}
if (yi < 0 || yi >= this.bitmap.height) {
i = -1;
}
return i;
}
/**
* Returns the hex color value of a pixel
* @param x the x coordinate
* @param y the y coordinate
* @returns the color of the pixel
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = new Jimp({ width: 3, height: 3, color: 0xffffffff });
*
* image.getPixelColor(1, 1); // 0xffffffff
* ```
*/
getPixelColor(x, y) {
if (typeof x !== "number" || typeof y !== "number") {
throw new Error("x and y must be numbers");
}
const idx = this.getPixelIndex(x, y);
return this.bitmap.data.readUInt32BE(idx);
}
/**
* Sets the hex colour value of a pixel
*
* @param hex color to set
* @param x the x coordinate
* @param y the y coordinate
*
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = new Jimp({ width: 3, height: 3, color: 0xffffffff });
*
* image.setPixelColor(0xff0000ff, 0, 0);
* ```
*/
setPixelColor(hex, x, y) {
if (typeof hex !== "number" ||
typeof x !== "number" ||
typeof y !== "number") {
throw new Error("hex, x and y must be numbers");
}
const idx = this.getPixelIndex(x, y);
this.bitmap.data.writeUInt32BE(hex, idx);
return this;
}
/**
* Determine if the image contains opaque pixels.
*
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = new Jimp({ width: 3, height: 3, color: 0xffffffaa });
* const image2 = new Jimp({ width: 3, height: 3, color: 0xff0000ff });
*
* image.hasAlpha(); // false
* image2.hasAlpha(); // true
* ```
*/
hasAlpha() {
const { width, height, data } = this.bitmap;
const byteLen = (width * height) << 2;
for (let idx = 3; idx < byteLen; idx += 4) {
if (data[idx] !== 0xff) {
return true;
}
}
return false;
}
/**
* Composites a source image over to this image respecting alpha channels
* @param src the source Jimp instance
* @param x the x position to blit the image
* @param y the y position to blit the image
* @param options determine what mode to use
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = new Jimp({ width: 10, height: 10, color: 0xffffffff });
* const image2 = new Jimp({ width: 3, height: 3, color: 0xff0000ff });
*
* image.composite(image2, 3, 3);
* ```
*/
composite(src, x = 0, y = 0, options = {}) {
return composite(this, src, x, y, options);
}
scan(x, y, w, h, f) {
return scan(this, x, y, w, h, f);
}
/**
* Iterate scan through a region of the bitmap
* @param x the x coordinate to begin the scan at
* @param y the y coordinate to begin the scan at
* @param w the width of the scan region
* @param h the height of the scan region
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = new Jimp({ width: 3, height: 3, color: 0xffffffff });
*
* for (const { x, y, idx, image } of j.scanIterator()) {
* // do something with the pixel
* }
* ```
*/
scanIterator(x = 0, y = 0, w = this.bitmap.width, h = this.bitmap.height) {
if (typeof x !== "number" || typeof y !== "number") {
throw new Error("x and y must be numbers");
}
if (typeof w !== "number" || typeof h !== "number") {
throw new Error("w and h must be numbers");
}
return scanIterator(this, x, y, w, h);
}
};
return CustomJimp;
}
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,IAAI,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,IAAI,MAAM,cAAc,CAAC;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,MAAM,WAAW,GAAW;IAC1B,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACrB,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;CACV,CAAC;AAEF;;GAEG;AACH,SAAS,qBAAqB,CAAC,WAAwB;IACrD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IACpD,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAEzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE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KAAK,IAAI,CAAC,IAAI,CAALine truncated
+3
View File
@@ -0,0 +1,3 @@
{
"type": "module"
}
+70
View File
@@ -0,0 +1,70 @@
import { RGBAColor } from "@jimp/types";
export declare function srcOver(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function dstOver(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function multiply(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function add(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function screen(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function overlay(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function darken(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function lighten(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function hardLight(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function difference(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare function exclusion(src: RGBAColor, dst: RGBAColor, ops?: number): {
r: number;
g: number;
b: number;
a: number;
};
export declare const names: readonly [typeof srcOver, typeof dstOver, typeof multiply, typeof add, typeof screen, typeof overlay, typeof darken, typeof lighten, typeof hardLight, typeof difference, typeof exclusion];
export type CompositeMode = (typeof names)[number];
//# sourceMappingURL=composite-modes.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"composite-modes.d.ts","sourceRoot":"","sources":["../../../src/utils/composite-modes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,wBAAgB,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,G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;
const r = (src.r * src.a + dst.r * dst.a * (1 - src.a)) / a;
const g = (src.g * src.a + dst.g * dst.a * (1 - src.a)) / a;
const b = (src.b * src.a + dst.b * dst.a * (1 - src.a)) / a;
return { r, g, b, a };
}
export function dstOver(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const r = (dst.r * dst.a + src.r * src.a * (1 - dst.a)) / a;
const g = (dst.g * dst.a + src.g * src.a * (1 - dst.a)) / a;
const b = (dst.b * dst.a + src.b * src.a * (1 - dst.a)) / a;
return { r, g, b, a };
}
export function multiply(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (sra * dra + sra * (1 - dst.a) + dra * (1 - src.a)) / a;
const g = (sga * dga + sga * (1 - dst.a) + dga * (1 - src.a)) / a;
const b = (sba * dba + sba * (1 - dst.a) + dba * (1 - src.a)) / a;
return { r, g, b, a };
}
export function add(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (sra + dra) / a;
const g = (sga + dga) / a;
const b = (sba + dba) / a;
return { r, g, b, a };
}
export function screen(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (sra * dst.a +
dra * src.a -
sra * dra +
sra * (1 - dst.a) +
dra * (1 - src.a)) /
a;
const g = (sga * dst.a +
dga * src.a -
sga * dga +
sga * (1 - dst.a) +
dga * (1 - src.a)) /
a;
const b = (sba * dst.a +
dba * src.a -
sba * dba +
sba * (1 - dst.a) +
dba * (1 - src.a)) /
a;
return { r, g, b, a };
}
export function overlay(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (2 * dra <= dst.a
? 2 * sra * dra + sra * (1 - dst.a) + dra * (1 - src.a)
: sra * (1 + dst.a) + dra * (1 + src.a) - 2 * dra * sra - dst.a * src.a) /
a;
const g = (2 * dga <= dst.a
? 2 * sga * dga + sga * (1 - dst.a) + dga * (1 - src.a)
: sga * (1 + dst.a) + dga * (1 + src.a) - 2 * dga * sga - dst.a * src.a) /
a;
const b = (2 * dba <= dst.a
? 2 * sba * dba + sba * (1 - dst.a) + dba * (1 - src.a)
: sba * (1 + dst.a) + dba * (1 + src.a) - 2 * dba * sba - dst.a * src.a) /
a;
return { r, g, b, a };
}
export function darken(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (Math.min(sra * dst.a, dra * src.a) +
sra * (1 - dst.a) +
dra * (1 - src.a)) /
a;
const g = (Math.min(sga * dst.a, dga * src.a) +
sga * (1 - dst.a) +
dga * (1 - src.a)) /
a;
const b = (Math.min(sba * dst.a, dba * src.a) +
sba * (1 - dst.a) +
dba * (1 - src.a)) /
a;
return { r, g, b, a };
}
export function lighten(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (Math.max(sra * dst.a, dra * src.a) +
sra * (1 - dst.a) +
dra * (1 - src.a)) /
a;
const g = (Math.max(sga * dst.a, dga * src.a) +
sga * (1 - dst.a) +
dga * (1 - src.a)) /
a;
const b = (Math.max(sba * dst.a, dba * src.a) +
sba * (1 - dst.a) +
dba * (1 - src.a)) /
a;
return { r, g, b, a };
}
export function hardLight(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (2 * sra <= src.a
? 2 * sra * dra + sra * (1 - dst.a) + dra * (1 - src.a)
: sra * (1 + dst.a) + dra * (1 + src.a) - 2 * dra * sra - dst.a * src.a) /
a;
const g = (2 * sga <= src.a
? 2 * sga * dga + sga * (1 - dst.a) + dga * (1 - src.a)
: sga * (1 + dst.a) + dga * (1 + src.a) - 2 * dga * sga - dst.a * src.a) /
a;
const b = (2 * sba <= src.a
? 2 * sba * dba + sba * (1 - dst.a) + dba * (1 - src.a)
: sba * (1 + dst.a) + dba * (1 + src.a) - 2 * dba * sba - dst.a * src.a) /
a;
return { r, g, b, a };
}
export function difference(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (sra + dra - 2 * Math.min(sra * dst.a, dra * src.a)) / a;
const g = (sga + dga - 2 * Math.min(sga * dst.a, dga * src.a)) / a;
const b = (sba + dba - 2 * Math.min(sba * dst.a, dba * src.a)) / a;
return { r, g, b, a };
}
export function exclusion(src, dst, ops = 1) {
src.a *= ops;
const a = dst.a + src.a - dst.a * src.a;
const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;
const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;
const r = (sra * dst.a +
dra * src.a -
2 * sra * dra +
sra * (1 - dst.a) +
dra * (1 - src.a)) /
a;
const g = (sga * dst.a +
dga * src.a -
2 * sga * dga +
sga * (1 - dst.a) +
dga * (1 - src.a)) /
a;
const b = (sba * dst.a +
dba * src.a -
2 * sba * dba +
sba * (1 - dst.a) +
dba * (1 - src.a)) /
a;
return { r, g, b, a };
}
export const names = [
srcOver,
dstOver,
multiply,
add,
screen,
overlay,
darken,
lighten,
hardLight,
difference,
exclusion,
];
//# sourceMappingURL=composite-modes.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"composite-modes.js","sourceRoot":"","sources":["../../../src/utils/composite-modes.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,OAAO,CAAC,GAAc,EAAE,GAAc,EAAE,GAAG,GAAG,CAAC;IAC7D,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC;IAEb,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IAExC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC5D,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC5D,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAE5D,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EA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CAAC,Line truncated
+8
View File
@@ -0,0 +1,8 @@
import { JimpClass } from "@jimp/types";
import { BlendMode } from "./constants.js";
export declare function composite<I extends JimpClass>(baseImage: I, src: I, x?: number, y?: number, options?: {
mode?: BlendMode;
opacitySource?: number;
opacityDest?: number;
}): I;
//# sourceMappingURL=composite.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"composite.d.ts","sourceRoot":"","sources":["../../../src/utils/composite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,SAAS,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI3C,wBAAgB,SAAS,CAAC,CAAC,SAAS,SAAS,EAC3C,SAAS,EAAE,CAAC,EACZ,GAAG,EAAE,CAAC,EACN,CAAC,SAAI,EACL,CAAC,SAAI,EACL,OAAO,GAAE;IACP,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACjB,KAqEP"}
+56
View File
@@ -0,0 +1,56 @@
import { Edge } from "@jimp/types";
import { BlendMode } from "./constants.js";
import * as compositeModes from "./composite-modes.js";
import { limit255 } from "@jimp/utils";
export function composite(baseImage, src, x = 0, y = 0, options = {}) {
if (!(src instanceof baseImage.constructor)) {
throw new Error("The source must be a Jimp image");
}
if (typeof x !== "number" || typeof y !== "number") {
throw new Error("x and y must be numbers");
}
const { mode = BlendMode.SRC_OVER } = options;
let { opacitySource = 1.0, opacityDest = 1.0 } = options;
if (typeof opacitySource !== "number" ||
opacitySource < 0 ||
opacitySource > 1) {
opacitySource = 1.0;
}
if (typeof opacityDest !== "number" || opacityDest < 0 || opacityDest > 1) {
opacityDest = 1.0;
}
const blendmode = compositeModes[mode];
// round input
x = Math.round(x);
y = Math.round(y);
if (opacityDest !== 1.0) {
baseImage.scan((_, __, idx) => {
const v = baseImage.bitmap.data[idx + 3] * opacityDest;
baseImage.bitmap.data[idx + 3] = v;
});
}
src.scan((sx, sy, idx) => {
const dstIdx = baseImage.getPixelIndex(x + sx, y + sy, Edge.CROP);
if (dstIdx === -1) {
// Skip target pixels outside of dst
return;
}
const blended = blendmode({
r: src.bitmap.data[idx + 0] / 255,
g: src.bitmap.data[idx + 1] / 255,
b: src.bitmap.data[idx + 2] / 255,
a: src.bitmap.data[idx + 3] / 255,
}, {
r: baseImage.bitmap.data[dstIdx + 0] / 255,
g: baseImage.bitmap.data[dstIdx + 1] / 255,
b: baseImage.bitmap.data[dstIdx + 2] / 255,
a: baseImage.bitmap.data[dstIdx + 3] / 255,
}, opacitySource);
baseImage.bitmap.data[dstIdx + 0] = limit255(blended.r * 255);
baseImage.bitmap.data[dstIdx + 1] = limit255(blended.g * 255);
baseImage.bitmap.data[dstIdx + 2] = limit255(blended.b * 255);
baseImage.bitmap.data[dstIdx + 3] = limit255(blended.a * 255);
});
return baseImage;
}
//# sourceMappingURL=composite.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"composite.js","sourceRoot":"","sources":["../../../src/utils/composite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAa,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,UAAU,SAAS,CACvB,SAAY,EACZ,GAAM,EACN,CAAC,GAAG,CAAC,EACL,CAAC,GAAG,CAAC,EACL,UAII,EAAE;IAEN,IAAI,CAAC,CAAC,GAAG,YAAY,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IAED,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QACnD,MAAM,IAAI,KAA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,CAAC,CAAC;QAC9D,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC"}
+85
View File
@@ -0,0 +1,85 @@
export declare enum HorizontalAlign {
LEFT = 1,
CENTER = 2,
RIGHT = 4
}
export declare enum VerticalAlign {
TOP = 8,
MIDDLE = 16,
BOTTOM = 32
}
/**
* How to blend two images together
*/
export declare enum BlendMode {
/**
* Composite the source image over the destination image.
* This is the default value. It represents the most intuitive case, where shapes are painted on top of what is below, with transparent areas showing the destination layer.
*/
SRC_OVER = "srcOver",
/** Composite the source image under the destination image. */
DST_OVER = "dstOver",
/**
* Multiply the color components of the source and destination images.
* This can only result in the same or darker colors (multiplying by white, 1.0, results in no change; multiplying by black, 0.0, results in black).
* When compositing two opaque images, this has similar effect to overlapping two transparencies on a projector.
*
* This mode is useful for coloring shadows.
*/
MULTIPLY = "multiply",
/**
* The Add mode adds the color information of the base layers and the blending layer.
* In digital terms, adding color increases the brightness.
*/
ADD = "add",
/**
* Multiply the inverse of the components of the source and destination images, and inverse the result.
* Inverting the components means that a fully saturated channel (opaque white) is treated as the value 0.0, and values normally treated as 0.0 (black, transparent) are treated as 1.0.
* This is essentially the same as modulate blend mode, but with the values of the colors inverted before the multiplication and the result being inverted back before rendering.
* This can only result in the same or lighter colors (multiplying by black, 1.0, results in no change; multiplying by white, 0.0, results in white). Similarly, in the alpha channel, it can only result in more opaque colors.
* This has similar effect to two projectors displaying their images on the same screen simultaneously.
*/
SCREEN = "screen",
/**
* Multiply the components of the source and destination images after adjusting them to favor the destination.
* Specifically, if the destination value is smaller, this multiplies it with the source value, whereas is the source value is smaller, it multiplies the inverse of the source value with the inverse of the destination value, then inverts the result.
* Inverting the components means that a fully saturated channel (opaque white) is treated as the value 0.0, and values normally treated as 0.0 (black, transparent) are treated as 1.0.
*
* The Overlay mode behaves like Screen mode in bright areas, and like Multiply mode in darker areas.
* With this mode, the bright areas will look brighter and the dark areas will look darker.
*/
OVERLAY = "overlay",
/**
* Composite the source and destination image by choosing the lowest value from each color channel.
* The opacity of the output image is computed in the same way as for srcOver.
*/
DARKEN = "darken",
/**
* Composite the source and destination image by choosing the highest value from each color channel.
* The opacity of the output image is computed in the same way as for srcOver.
*/
LIGHTEN = "lighten",
/**
* Multiply the components of the source and destination images after adjusting them to favor the source.
* Specifically, if the source value is smaller, this multiplies it with the destination value, whereas is the destination value is smaller, it multiplies the inverse of the destination value with the inverse of the source value, then inverts the result.
* Inverting the components means that a fully saturated channel (opaque white) is treated as the value 0.0, and values normally treated as 0.0 (black, transparent) are treated as 1.0.
*
* The effect of the Hard light mode depends on the density of the superimposed color. Using bright colors on the blending layer will create a brighter effect like the Screen modes, while dark colors will create darker colors like the Multiply mode.
*/
HARD_LIGHT = "hardLight",
/**
* Subtract the smaller value from the bigger value for each channel.
* Compositing black has no effect; compositing white inverts the colors of the other image.
* The opacity of the output image is computed in the same way as for srcOver.
* The effect is similar to exclusion but harsher.
*/
DIFFERENCE = "difference",
/**
* Subtract double the product of the two images from the sum of the two images.
* Compositing black has no effect; compositing white inverts the colors of the other image.
* The opacity of the output image is computed in the same way as for srcOver.
* The effect is similar to difference but softer.
*/
EXCLUSION = "exclusion"
}
//# sourceMappingURL=constants.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/utils/constants.ts"],"names":[],"mappings":"AACA,oBAAY,eAAe;IACzB,IAAI,IAAI;IACR,MAAM,IAAI;IACV,KAAK,IAAI;CACV;AAGD,oBAAY,aAAa;IACvB,GAAG,IAAI;IACP,MAAM,KAAK;IACX,MAAM,KAAK;CACZ;AAED;;GAEG;AACH,oBAAY,SAAS;IACnB;;;OAGG;IACH,QAAQ,YAAY;IACpB,8DAA8D;IAC9D,QAAQ,YAAY;IACpB;;;;;;OAMG;IACH,QAAQ,aAAa;IACrB;;;OAGG;IACH,GAAG,QAAQ;IACX;;;;;;OAMG;IACH,MAAM,WAAW;IACjB;;;;;;;OAOG;IACH,OAAO,YAAY;IACnB;;;OAGG;IACH,MAAM,WAAW;IACjB;;;OAGG;IACH,OAAO,YAAY;IACnB;;;;;;OAMG;IACH,UAAU,cAAc;IACxB;;;;;OAKG;IACH,UAAU,eAAe;IACzB;;;;;OAKG;IACH,SAAS,cAAc;CACxB"}
+90
View File
@@ -0,0 +1,90 @@
/* Horizontal align modes for cover, contain, bit masks */
export var HorizontalAlign;
(function (HorizontalAlign) {
HorizontalAlign[HorizontalAlign["LEFT"] = 1] = "LEFT";
HorizontalAlign[HorizontalAlign["CENTER"] = 2] = "CENTER";
HorizontalAlign[HorizontalAlign["RIGHT"] = 4] = "RIGHT";
})(HorizontalAlign || (HorizontalAlign = {}));
/* Vertical align modes for cover, contain, bit masks */
export var VerticalAlign;
(function (VerticalAlign) {
VerticalAlign[VerticalAlign["TOP"] = 8] = "TOP";
VerticalAlign[VerticalAlign["MIDDLE"] = 16] = "MIDDLE";
VerticalAlign[VerticalAlign["BOTTOM"] = 32] = "BOTTOM";
})(VerticalAlign || (VerticalAlign = {}));
/**
* How to blend two images together
*/
export var BlendMode;
(function (BlendMode) {
/**
* Composite the source image over the destination image.
* This is the default value. It represents the most intuitive case, where shapes are painted on top of what is below, with transparent areas showing the destination layer.
*/
BlendMode["SRC_OVER"] = "srcOver";
/** Composite the source image under the destination image. */
BlendMode["DST_OVER"] = "dstOver";
/**
* Multiply the color components of the source and destination images.
* This can only result in the same or darker colors (multiplying by white, 1.0, results in no change; multiplying by black, 0.0, results in black).
* When compositing two opaque images, this has similar effect to overlapping two transparencies on a projector.
*
* This mode is useful for coloring shadows.
*/
BlendMode["MULTIPLY"] = "multiply";
/**
* The Add mode adds the color information of the base layers and the blending layer.
* In digital terms, adding color increases the brightness.
*/
BlendMode["ADD"] = "add";
/**
* Multiply the inverse of the components of the source and destination images, and inverse the result.
* Inverting the components means that a fully saturated channel (opaque white) is treated as the value 0.0, and values normally treated as 0.0 (black, transparent) are treated as 1.0.
* This is essentially the same as modulate blend mode, but with the values of the colors inverted before the multiplication and the result being inverted back before rendering.
* This can only result in the same or lighter colors (multiplying by black, 1.0, results in no change; multiplying by white, 0.0, results in white). Similarly, in the alpha channel, it can only result in more opaque colors.
* This has similar effect to two projectors displaying their images on the same screen simultaneously.
*/
BlendMode["SCREEN"] = "screen";
/**
* Multiply the components of the source and destination images after adjusting them to favor the destination.
* Specifically, if the destination value is smaller, this multiplies it with the source value, whereas is the source value is smaller, it multiplies the inverse of the source value with the inverse of the destination value, then inverts the result.
* Inverting the components means that a fully saturated channel (opaque white) is treated as the value 0.0, and values normally treated as 0.0 (black, transparent) are treated as 1.0.
*
* The Overlay mode behaves like Screen mode in bright areas, and like Multiply mode in darker areas.
* With this mode, the bright areas will look brighter and the dark areas will look darker.
*/
BlendMode["OVERLAY"] = "overlay";
/**
* Composite the source and destination image by choosing the lowest value from each color channel.
* The opacity of the output image is computed in the same way as for srcOver.
*/
BlendMode["DARKEN"] = "darken";
/**
* Composite the source and destination image by choosing the highest value from each color channel.
* The opacity of the output image is computed in the same way as for srcOver.
*/
BlendMode["LIGHTEN"] = "lighten";
/**
* Multiply the components of the source and destination images after adjusting them to favor the source.
* Specifically, if the source value is smaller, this multiplies it with the destination value, whereas is the destination value is smaller, it multiplies the inverse of the destination value with the inverse of the source value, then inverts the result.
* Inverting the components means that a fully saturated channel (opaque white) is treated as the value 0.0, and values normally treated as 0.0 (black, transparent) are treated as 1.0.
*
* The effect of the Hard light mode depends on the density of the superimposed color. Using bright colors on the blending layer will create a brighter effect like the Screen modes, while dark colors will create darker colors like the Multiply mode.
*/
BlendMode["HARD_LIGHT"] = "hardLight";
/**
* Subtract the smaller value from the bigger value for each channel.
* Compositing black has no effect; compositing white inverts the colors of the other image.
* The opacity of the output image is computed in the same way as for srcOver.
* The effect is similar to exclusion but harsher.
*/
BlendMode["DIFFERENCE"] = "difference";
/**
* Subtract double the product of the two images from the sum of the two images.
* Compositing black has no effect; compositing white inverts the colors of the other image.
* The opacity of the output image is computed in the same way as for srcOver.
* The effect is similar to difference but softer.
*/
BlendMode["EXCLUSION"] = "exclusion";
})(BlendMode || (BlendMode = {}));
//# sourceMappingURL=constants.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,MAAM,CAAN,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,qDAAQ,CAAA;IACR,yDAAU,CAAA;IACV,uDAAS,CAAA;AACX,CAAC,EAJW,eAAe,KAAf,eAAe,QAI1B;AAED,wDAAwD;AACxD,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,+CAAO,CAAA;IACP,sDAAW,CAAA;IACX,sDAAW,CAAA;AACb,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,SAsEX;AAtED,WAAY,SAAS;IACnB;;;OAGG;IACH,iCAAoB,CAAA;IACpB,8DAA8D;IAC9D,iCAAoB,CAAA;IACpB;;;;;;OAMG;IACH,kCAAqB,CAAA;IACrB;;;OAGG;IACH,wBAAW,CAAA;IACX;;;;;;OAMG;IACH,8BAAiB,CAAA;IACjB;;;;;;;OAOG;IACH,gCAAmB,CAAA;IACnB;;;OAGG;IACH,8BAAiB,CAAA;IACjB;;;OAGG;IACH,gCAAmB,CAAA;IACnB;;;;;;OAMG;IACH,qCAAwB,CAAA;IACxB;;;;;OAKG;IACH,sCAAyB,CAAA;IACzB;;;;;OAKG;IACH,oCAAuB,CAAA;AACzB,CAAC,EAtEW,SAAS,KAAT,SAAS,QAsEpB"}
+11
View File
@@ -0,0 +1,11 @@
import { JimpClass } from "@jimp/types";
/**
* Obtains image orientation from EXIF metadata.
*
* @param img a Jimp image object
* @returns a number 1-8 representing EXIF orientation,
* in particular 1 if orientation tag is missing
*/
export declare function getExifOrientation<I extends JimpClass>(img: I): number;
export declare function attemptExifRotate<I extends JimpClass>(image: I, buffer: Buffer): Promise<void>;
//# sourceMappingURL=image-bitmap.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"image-bitmap.d.ts","sourceRoot":"","sources":["../../../src/utils/image-bitmap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,SAAS,EAAE,GAAG,EAAE,CAAC,UAG7D;AA+HD,wBAAsB,iBAAiB,CAAC,CAAC,SAAS,SAAS,EACzD,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,MAAM,iBAUf"}
+122
View File
@@ -0,0 +1,122 @@
import EXIFParser from "exif-parser";
/**
* Obtains image orientation from EXIF metadata.
*
* @param img a Jimp image object
* @returns a number 1-8 representing EXIF orientation,
* in particular 1 if orientation tag is missing
*/
export function getExifOrientation(img) {
const _exif = img._exif;
return (_exif && _exif.tags && _exif.tags.Orientation) || 1;
}
/**
* Returns a function which translates EXIF-rotated coordinates into
* non-rotated ones.
*
* Transformation reference: http://sylvana.net/jpegcrop/exif_orientation.html.
*
* @param img a Jimp image object
* @returns transformation function for transformBitmap().
*/
function getExifOrientationTransformation(img) {
const w = img.bitmap.width;
const h = img.bitmap.height;
switch (getExifOrientation(img)) {
case 1: // Horizontal (normal)
// does not need to be supported here
return null;
case 2: // Mirror horizontal
return function (x, y) {
return [w - x - 1, y];
};
case 3: // Rotate 180
return function (x, y) {
return [w - x - 1, h - y - 1];
};
case 4: // Mirror vertical
return function (x, y) {
return [x, h - y - 1];
};
case 5: // Mirror horizontal and rotate 270 CW
return function (x, y) {
return [y, x];
};
case 6: // Rotate 90 CW
return function (x, y) {
return [y, h - x - 1];
};
case 7: // Mirror horizontal and rotate 90 CW
return function (x, y) {
return [w - y - 1, h - x - 1];
};
case 8: // Rotate 270 CW
return function (x, y) {
return [w - y - 1, x];
};
default:
return null;
}
}
/**
* Transforms bitmap in place (moves pixels around) according to given
* transformation function.
*
* @param img a Jimp image object, which bitmap is supposed to
* be transformed
* @param width bitmap width after the transformation
* @param height bitmap height after the transformation
* @param transformation transformation function which defines pixel
* mapping between new and source bitmap. It takes a pair of coordinates
* in the target, and returns a respective pair of coordinates in
* the source bitmap, i.e. has following form:
* `function(new_x, new_y) { return [src_x, src_y] }`.
*/
function transformBitmap(img, width, height, transformation) {
// Underscore-prefixed values are related to the source bitmap
// Their counterparts with no prefix are related to the target bitmap
const _data = img.bitmap.data;
const _width = img.bitmap.width;
const data = Buffer.alloc(_data.length);
for (let x = 0; x < width; x++) {
for (let y = 0; y < height; y++) {
const [_x, _y] = transformation(x, y);
const idx = (width * y + x) << 2;
const _idx = (_width * _y + _x) << 2;
const pixel = _data.readUInt32BE(_idx);
data.writeUInt32BE(pixel, idx);
}
}
img.bitmap.data = data;
img.bitmap.width = width;
img.bitmap.height = height;
// @ts-expect-error Accessing private property
img._exif.tags.Orientation = 1;
}
/**
* Automagically rotates an image based on its EXIF data (if present).
* @param img a Jimp image object
*/
function exifRotate(img) {
if (getExifOrientation(img) < 2) {
return;
}
const transformation = getExifOrientationTransformation(img);
const swapDimensions = getExifOrientation(img) > 4;
const newWidth = swapDimensions ? img.bitmap.height : img.bitmap.width;
const newHeight = swapDimensions ? img.bitmap.width : img.bitmap.height;
if (transformation) {
transformBitmap(img, newWidth, newHeight, transformation);
}
}
export async function attemptExifRotate(image, buffer) {
try {
image._exif =
EXIFParser.create(buffer).parse();
exifRotate(image); // EXIF data
}
catch {
// do nothing
}
}
//# sourceMappingURL=image-bitmap.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"image-bitmap.js","sourceRoot":"","sources":["../../../src/utils/image-bitmap.ts"],"names":[],"mappings":"AAAA,OAAO,UAAwB,MAAM,aAAa,CAAC;AAGnD;;;;;;GAMG;AACH,MAAM,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,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,aAAa;IACf,CAAC;AACH,CAAC"}
+2
View File
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=mime.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"mime.d.ts","sourceRoot":"","sources":["../../../src/utils/mime.ts"],"names":[],"mappings":""}
+29
View File
@@ -0,0 +1,29 @@
// const mimeTypes = {};
export {};
// const findType = (extension: string) =>
// Object.entries(mimeTypes).find((type) => type[1].includes(extension)) || [];
// export const addType = (mime: string, extensions: string[]) => {
// mimeTypes[mime] = extensions;
// };
// /**
// * Lookup a mime type based on extension
// * @param {string} path path to find extension for
// * @returns {string} mime found mime type
// */
// export const getType = (path: string) => {
// const pathParts = path.split("/").slice(-1);
// const extension = pathParts[pathParts.length - 1]?.split(".").pop();
// if (!extension) {
// return null;
// }
// const type = findType(extension);
// return type[0];
// };
// /**
// * Return file extension associated with a mime type
// * @param {string} type mime type to look up
// * @returns {string} extension file extension
// */
// export const getExtension = (type: string) =>
// (mimeTypes[type.toLowerCase()] || [])[0];
//# sourceMappingURL=mime.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"mime.js","sourceRoot":"","sources":["../../../src/utils/mime.ts"],"names":[],"mappings":"AAAA,wBAAwB;;AAExB,0CAA0C;AAC1C,iFAAiF;AAEjF,mEAAmE;AACnE,kCAAkC;AAClC,KAAK;AAEL,MAAM;AACN,2CAA2C;AAC3C,qDAAqD;AACrD,4CAA4C;AAC5C,MAAM;AACN,6CAA6C;AAC7C,iDAAiD;AACjD,yEAAyE;AAEzE,sBAAsB;AACtB,mBAAmB;AACnB,MAAM;AAEN,sCAAsC;AAEtC,oBAAoB;AACpB,KAAK;AAEL,MAAM;AACN,uDAAuD;AACvD,+CAA+C;AAC/C,gDAAgD;AAChD,MAAM;AACN,gDAAgD;AAChD,8CAA8C"}