UNPKG

jimp

Version:

An image processing library written entirely in JavaScript.

220 lines • 10.3 kB
"use strict"; /** * @module jimp */ 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 () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.cssColorToHex = exports.limit255 = exports.colorDiff = exports.rgbaToInt = exports.intToRGBA = exports.diff = exports.measureTextHeight = exports.measureText = exports.loadFont = exports.Edge = exports.BlendMode = exports.VerticalAlign = exports.HorizontalAlign = exports.BmpCompression = exports.PNGFilterType = exports.PNGColorType = exports.parseCubeLut = exports.decodeBlurhash = exports.compareHashes = exports.distance = exports.otsuThreshold = exports.ResizeStrategy = exports.ColorActionName = exports.Jimp = exports.JimpMime = exports.defaultFormats = exports.defaultPlugins = void 0; // import { Jimp } from "@jimp/core"; const js_bmp_1 = __importStar(require("@jimp/js-bmp")); const js_gif_1 = __importDefault(require("@jimp/js-gif")); const js_ico_1 = __importStar(require("@jimp/js-ico")); const js_jpeg_1 = __importDefault(require("@jimp/js-jpeg")); const js_png_1 = __importDefault(require("@jimp/js-png")); const js_tiff_1 = __importDefault(require("@jimp/js-tiff")); const blit = __importStar(require("@jimp/plugin-blit")); const blur = __importStar(require("@jimp/plugin-blur")); const border = __importStar(require("@jimp/plugin-border")); const circle = __importStar(require("@jimp/plugin-circle")); const color = __importStar(require("@jimp/plugin-color")); const contain = __importStar(require("@jimp/plugin-contain")); const cover = __importStar(require("@jimp/plugin-cover")); const crop = __importStar(require("@jimp/plugin-crop")); const displace = __importStar(require("@jimp/plugin-displace")); const dither = __importStar(require("@jimp/plugin-dither")); const draw = __importStar(require("@jimp/plugin-draw")); const fisheye = __importStar(require("@jimp/plugin-fisheye")); const flip = __importStar(require("@jimp/plugin-flip")); const hash = __importStar(require("@jimp/plugin-hash")); const lut = __importStar(require("@jimp/plugin-lut")); const mask = __importStar(require("@jimp/plugin-mask")); const morphology = __importStar(require("@jimp/plugin-morphology")); const print = __importStar(require("@jimp/plugin-print")); const resize = __importStar(require("@jimp/plugin-resize")); const rotate = __importStar(require("@jimp/plugin-rotate")); const threshold = __importStar(require("@jimp/plugin-threshold")); const quantize = __importStar(require("@jimp/plugin-quantize")); const core_1 = require("@jimp/core"); exports.defaultPlugins = [ blit.methods, blur.methods, border.methods, circle.methods, color.methods, contain.methods, cover.methods, crop.methods, displace.methods, dither.methods, draw.methods, fisheye.methods, flip.methods, hash.methods, lut.methods, mask.methods, morphology.methods, print.methods, resize.methods, rotate.methods, threshold.methods, quantize.methods, ]; exports.defaultFormats = [js_bmp_1.default, js_bmp_1.msBmp, js_gif_1.default, js_ico_1.default, js_ico_1.msIcon, js_jpeg_1.default, js_png_1.default, js_tiff_1.default]; /** Convenience object for getting the MIME types of the default formats */ exports.JimpMime = { bmp: (0, js_bmp_1.default)().mime, gif: (0, js_gif_1.default)().mime, ico: (0, js_ico_1.default)().mime, jpeg: (0, js_jpeg_1.default)().mime, png: (0, js_png_1.default)().mime, tiff: (0, js_tiff_1.default)().mime, }; // TODO: This doesn't document the constructor of the class /** * @class * * A `Jimp` class enables you to:class * * - Read an image into a "bit map" (a collection of pixels) * - Modify the bit map through methods that change the pixels * - Write the bit map back to an image buffer * * @example * * #### Basic * * You can use the Jimp class to make empty images. * This is useful for when you want to create an image that composed of other images on top of a background. * * ```ts * import { Jimp } from "jimp"; * * const image = new Jimp({ width: 256, height: 256, color: 0xffffffff }); * const image2 = new Jimp({ width: 100, height: 100, color: 0xff0000ff }); * * image.composite(image2, 50, 50); * ``` * * #### Node * * You can use jimp in Node.js. * For example you can read an image from a file and resize it and * then write it back to a file. * * ```ts * import { Jimp } from "jimp"; * import { promises as fs } from "fs"; * * const image = await Jimp.read("test/image.png"); * * image.resize({ w: 256, h: 100 }); * image.greyscale(); * * await image.write('test/output.png'); * ``` * * #### Browser * * You can use jimp in the browser by reading files from URLs * * ```ts * import { Jimp } from "jimp"; * * const image = await Jimp.read("https://upload.wikimedia.org/wikipedia/commons/0/01/Bot-Test.jpg"); * * image.resize({ w: 256, h: 100 }); * image.greyscale(); * * const canvas = document.createElement("canvas"); * * canvas.width = image.bitmap.width; * canvas.height = image.bitmap.height; * * const ctx = canvas.getContext("2d"); * const imageData = new ImageData( * new Uint8ClampedArray(image.bitmap.data), * image.bitmap.width, * image.bitmap.height * ); * * ctx.putImageData(imageData, 0, 0); * * document.body.appendChild(canvas); * ``` */ exports.Jimp = (0, core_1.createJimp)({ formats: exports.defaultFormats, plugins: exports.defaultPlugins, }); var plugin_color_1 = require("@jimp/plugin-color"); Object.defineProperty(exports, "ColorActionName", { enumerable: true, get: function () { return plugin_color_1.ColorActionName; } }); var plugin_resize_1 = require("@jimp/plugin-resize"); Object.defineProperty(exports, "ResizeStrategy", { enumerable: true, get: function () { return plugin_resize_1.ResizeStrategy; } }); var plugin_threshold_1 = require("@jimp/plugin-threshold"); Object.defineProperty(exports, "otsuThreshold", { enumerable: true, get: function () { return plugin_threshold_1.otsuThreshold; } }); var plugin_hash_1 = require("@jimp/plugin-hash"); Object.defineProperty(exports, "distance", { enumerable: true, get: function () { return plugin_hash_1.distance; } }); Object.defineProperty(exports, "compareHashes", { enumerable: true, get: function () { return plugin_hash_1.compareHashes; } }); Object.defineProperty(exports, "decodeBlurhash", { enumerable: true, get: function () { return plugin_hash_1.decodeBlurhash; } }); var plugin_lut_1 = require("@jimp/plugin-lut"); Object.defineProperty(exports, "parseCubeLut", { enumerable: true, get: function () { return plugin_lut_1.parseCubeLut; } }); var js_png_2 = require("@jimp/js-png"); Object.defineProperty(exports, "PNGColorType", { enumerable: true, get: function () { return js_png_2.PNGColorType; } }); Object.defineProperty(exports, "PNGFilterType", { enumerable: true, get: function () { return js_png_2.PNGFilterType; } }); var js_bmp_2 = require("@jimp/js-bmp"); Object.defineProperty(exports, "BmpCompression", { enumerable: true, get: function () { return js_bmp_2.BmpCompression; } }); var core_2 = require("@jimp/core"); Object.defineProperty(exports, "HorizontalAlign", { enumerable: true, get: function () { return core_2.HorizontalAlign; } }); Object.defineProperty(exports, "VerticalAlign", { enumerable: true, get: function () { return core_2.VerticalAlign; } }); Object.defineProperty(exports, "BlendMode", { enumerable: true, get: function () { return core_2.BlendMode; } }); var types_1 = require("@jimp/types"); Object.defineProperty(exports, "Edge", { enumerable: true, get: function () { return types_1.Edge; } }); var load_font_1 = require("@jimp/plugin-print/load-font"); Object.defineProperty(exports, "loadFont", { enumerable: true, get: function () { return load_font_1.loadFont; } }); var plugin_print_1 = require("@jimp/plugin-print"); Object.defineProperty(exports, "measureText", { enumerable: true, get: function () { return plugin_print_1.measureText; } }); Object.defineProperty(exports, "measureTextHeight", { enumerable: true, get: function () { return plugin_print_1.measureTextHeight; } }); var diff_1 = require("@jimp/diff"); Object.defineProperty(exports, "diff", { enumerable: true, get: function () { return diff_1.diff; } }); var utils_1 = require("@jimp/utils"); Object.defineProperty(exports, "intToRGBA", { enumerable: true, get: function () { return utils_1.intToRGBA; } }); Object.defineProperty(exports, "rgbaToInt", { enumerable: true, get: function () { return utils_1.rgbaToInt; } }); Object.defineProperty(exports, "colorDiff", { enumerable: true, get: function () { return utils_1.colorDiff; } }); Object.defineProperty(exports, "limit255", { enumerable: true, get: function () { return utils_1.limit255; } }); Object.defineProperty(exports, "cssColorToHex", { enumerable: true, get: function () { return utils_1.cssColorToHex; } }); //# sourceMappingURL=index.js.map