Path: blob/master/node_modules/@jimp/png/dist/index.js
1126 views
"use strict";12var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");34Object.defineProperty(exports, "__esModule", {5value: true6});7exports["default"] = void 0;89var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));1011var _pngjs = require("pngjs");1213var _utils = require("@jimp/utils");1415var MIME_TYPE = 'image/png'; // PNG filter types1617var PNG_FILTER_AUTO = -1;18var PNG_FILTER_NONE = 0;19var PNG_FILTER_SUB = 1;20var PNG_FILTER_UP = 2;21var PNG_FILTER_AVERAGE = 3;22var PNG_FILTER_PATH = 4;2324var _default = function _default() {25return {26mime: (0, _defineProperty2["default"])({}, MIME_TYPE, ['png']),27constants: {28MIME_PNG: MIME_TYPE,29PNG_FILTER_AUTO: PNG_FILTER_AUTO,30PNG_FILTER_NONE: PNG_FILTER_NONE,31PNG_FILTER_SUB: PNG_FILTER_SUB,32PNG_FILTER_UP: PNG_FILTER_UP,33PNG_FILTER_AVERAGE: PNG_FILTER_AVERAGE,34PNG_FILTER_PATH: PNG_FILTER_PATH35},36hasAlpha: (0, _defineProperty2["default"])({}, MIME_TYPE, true),37decoders: (0, _defineProperty2["default"])({}, MIME_TYPE, _pngjs.PNG.sync.read),38encoders: (0, _defineProperty2["default"])({}, MIME_TYPE, function (data) {39var png = new _pngjs.PNG({40width: data.bitmap.width,41height: data.bitmap.height42});43png.data = data.bitmap.data;44return _pngjs.PNG.sync.write(png, {45width: data.bitmap.width,46height: data.bitmap.height,47deflateLevel: data._deflateLevel,48deflateStrategy: data._deflateStrategy,49filterType: data._filterType,50colorType: typeof data._colorType === 'number' ? data._colorType : data._rgba ? 6 : 2,51inputHasAlpha: data._rgba52});53}),54"class": {55_deflateLevel: 9,56_deflateStrategy: 3,57_filterType: PNG_FILTER_AUTO,58_colorType: null,5960/**61* Sets the deflate level used when saving as PNG format (default is 9)62* @param {number} l Deflate level to use 0-9. 0 is no compression. 9 (default) is maximum compression.63* @param {function(Error, Jimp)} cb (optional) a callback for when complete64* @returns {Jimp} this for chaining of methods65*/66deflateLevel: function deflateLevel(l, cb) {67if (typeof l !== 'number') {68return _utils.throwError.call(this, 'l must be a number', cb);69}7071if (l < 0 || l > 9) {72return _utils.throwError.call(this, 'l must be a number 0 - 9', cb);73}7475this._deflateLevel = Math.round(l);7677if ((0, _utils.isNodePattern)(cb)) {78cb.call(this, null, this);79}8081return this;82},8384/**85* Sets the deflate strategy used when saving as PNG format (default is 3)86* @param {number} s Deflate strategy to use 0-3.87* @param {function(Error, Jimp)} cb (optional) a callback for when complete88* @returns {Jimp} this for chaining of methods89*/90deflateStrategy: function deflateStrategy(s, cb) {91if (typeof s !== 'number') {92return _utils.throwError.call(this, 's must be a number', cb);93}9495if (s < 0 || s > 3) {96return _utils.throwError.call(this, 's must be a number 0 - 3', cb);97}9899this._deflateStrategy = Math.round(s);100101if ((0, _utils.isNodePattern)(cb)) {102cb.call(this, null, this);103}104105return this;106},107108/**109* Sets the filter type used when saving as PNG format (default is automatic filters)110* @param {number} f The quality to use -1-4.111* @param {function(Error, Jimp)} cb (optional) a callback for when complete112* @returns {Jimp} this for chaining of methods113*/114filterType: function filterType(f, cb) {115if (typeof f !== 'number') {116return _utils.throwError.call(this, 'n must be a number', cb);117}118119if (f < -1 || f > 4) {120return _utils.throwError.call(this, 'n must be -1 (auto) or a number 0 - 4', cb);121}122123this._filterType = Math.round(f);124125if ((0, _utils.isNodePattern)(cb)) {126cb.call(this, null, this);127}128129return this;130},131132/**133* Sets the color type used when saving as PNG format134* @param {number} s color type to use 0, 2, 4, 6.135* @param {function(Error, Jimp)} cb (optional) a callback for when complete136* @returns {Jimp} this for chaining of methods137*/138colorType: function colorType(s, cb) {139if (typeof s !== 'number') {140return _utils.throwError.call(this, 's must be a number', cb);141}142143if (s !== 0 && s !== 2 && s !== 4 && s !== 6) {144return _utils.throwError.call(this, 's must be a number 0, 2, 4, 6.', cb);145}146147this._colorType = Math.round(s);148149if ((0, _utils.isNodePattern)(cb)) {150cb.call(this, null, this);151}152153return this;154}155}156};157};158159exports["default"] = _default;160module.exports = exports.default;161//# sourceMappingURL=index.js.map162163