Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/png/dist/index.js
1126 views
1
"use strict";
2
3
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5
Object.defineProperty(exports, "__esModule", {
6
value: true
7
});
8
exports["default"] = void 0;
9
10
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
12
var _pngjs = require("pngjs");
13
14
var _utils = require("@jimp/utils");
15
16
var MIME_TYPE = 'image/png'; // PNG filter types
17
18
var PNG_FILTER_AUTO = -1;
19
var PNG_FILTER_NONE = 0;
20
var PNG_FILTER_SUB = 1;
21
var PNG_FILTER_UP = 2;
22
var PNG_FILTER_AVERAGE = 3;
23
var PNG_FILTER_PATH = 4;
24
25
var _default = function _default() {
26
return {
27
mime: (0, _defineProperty2["default"])({}, MIME_TYPE, ['png']),
28
constants: {
29
MIME_PNG: MIME_TYPE,
30
PNG_FILTER_AUTO: PNG_FILTER_AUTO,
31
PNG_FILTER_NONE: PNG_FILTER_NONE,
32
PNG_FILTER_SUB: PNG_FILTER_SUB,
33
PNG_FILTER_UP: PNG_FILTER_UP,
34
PNG_FILTER_AVERAGE: PNG_FILTER_AVERAGE,
35
PNG_FILTER_PATH: PNG_FILTER_PATH
36
},
37
hasAlpha: (0, _defineProperty2["default"])({}, MIME_TYPE, true),
38
decoders: (0, _defineProperty2["default"])({}, MIME_TYPE, _pngjs.PNG.sync.read),
39
encoders: (0, _defineProperty2["default"])({}, MIME_TYPE, function (data) {
40
var png = new _pngjs.PNG({
41
width: data.bitmap.width,
42
height: data.bitmap.height
43
});
44
png.data = data.bitmap.data;
45
return _pngjs.PNG.sync.write(png, {
46
width: data.bitmap.width,
47
height: data.bitmap.height,
48
deflateLevel: data._deflateLevel,
49
deflateStrategy: data._deflateStrategy,
50
filterType: data._filterType,
51
colorType: typeof data._colorType === 'number' ? data._colorType : data._rgba ? 6 : 2,
52
inputHasAlpha: data._rgba
53
});
54
}),
55
"class": {
56
_deflateLevel: 9,
57
_deflateStrategy: 3,
58
_filterType: PNG_FILTER_AUTO,
59
_colorType: null,
60
61
/**
62
* Sets the deflate level used when saving as PNG format (default is 9)
63
* @param {number} l Deflate level to use 0-9. 0 is no compression. 9 (default) is maximum compression.
64
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
65
* @returns {Jimp} this for chaining of methods
66
*/
67
deflateLevel: function deflateLevel(l, cb) {
68
if (typeof l !== 'number') {
69
return _utils.throwError.call(this, 'l must be a number', cb);
70
}
71
72
if (l < 0 || l > 9) {
73
return _utils.throwError.call(this, 'l must be a number 0 - 9', cb);
74
}
75
76
this._deflateLevel = Math.round(l);
77
78
if ((0, _utils.isNodePattern)(cb)) {
79
cb.call(this, null, this);
80
}
81
82
return this;
83
},
84
85
/**
86
* Sets the deflate strategy used when saving as PNG format (default is 3)
87
* @param {number} s Deflate strategy to use 0-3.
88
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
89
* @returns {Jimp} this for chaining of methods
90
*/
91
deflateStrategy: function deflateStrategy(s, cb) {
92
if (typeof s !== 'number') {
93
return _utils.throwError.call(this, 's must be a number', cb);
94
}
95
96
if (s < 0 || s > 3) {
97
return _utils.throwError.call(this, 's must be a number 0 - 3', cb);
98
}
99
100
this._deflateStrategy = Math.round(s);
101
102
if ((0, _utils.isNodePattern)(cb)) {
103
cb.call(this, null, this);
104
}
105
106
return this;
107
},
108
109
/**
110
* Sets the filter type used when saving as PNG format (default is automatic filters)
111
* @param {number} f The quality to use -1-4.
112
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
113
* @returns {Jimp} this for chaining of methods
114
*/
115
filterType: function filterType(f, cb) {
116
if (typeof f !== 'number') {
117
return _utils.throwError.call(this, 'n must be a number', cb);
118
}
119
120
if (f < -1 || f > 4) {
121
return _utils.throwError.call(this, 'n must be -1 (auto) or a number 0 - 4', cb);
122
}
123
124
this._filterType = Math.round(f);
125
126
if ((0, _utils.isNodePattern)(cb)) {
127
cb.call(this, null, this);
128
}
129
130
return this;
131
},
132
133
/**
134
* Sets the color type used when saving as PNG format
135
* @param {number} s color type to use 0, 2, 4, 6.
136
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
137
* @returns {Jimp} this for chaining of methods
138
*/
139
colorType: function colorType(s, cb) {
140
if (typeof s !== 'number') {
141
return _utils.throwError.call(this, 's must be a number', cb);
142
}
143
144
if (s !== 0 && s !== 2 && s !== 4 && s !== 6) {
145
return _utils.throwError.call(this, 's must be a number 0, 2, 4, 6.', cb);
146
}
147
148
this._colorType = Math.round(s);
149
150
if ((0, _utils.isNodePattern)(cb)) {
151
cb.call(this, null, this);
152
}
153
154
return this;
155
}
156
}
157
};
158
};
159
160
exports["default"] = _default;
161
module.exports = exports.default;
162
//# sourceMappingURL=index.js.map
163