Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/jpeg/src/index.js
1126 views
1
import JPEG from 'jpeg-js';
2
import { throwError, isNodePattern } from '@jimp/utils';
3
4
const MIME_TYPE = 'image/jpeg';
5
6
export default () => ({
7
mime: { [MIME_TYPE]: ['jpeg', 'jpg', 'jpe'] },
8
9
constants: {
10
MIME_JPEG: MIME_TYPE
11
},
12
13
decoders: {
14
[MIME_TYPE]: JPEG.decode
15
},
16
17
encoders: {
18
[MIME_TYPE]: image => JPEG.encode(image.bitmap, image._quality).data
19
},
20
21
class: {
22
// The quality to be used when saving JPEG images
23
_quality: 100,
24
/**
25
* Sets the quality of the image when saving as JPEG format (default is 100)
26
* @param {number} n The quality to use 0-100
27
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
28
* @returns {Jimp} this for chaining of methods
29
*/
30
quality(n, cb) {
31
if (typeof n !== 'number') {
32
return throwError.call(this, 'n must be a number', cb);
33
}
34
35
if (n < 0 || n > 100) {
36
return throwError.call(this, 'n must be a number 0 - 100', cb);
37
}
38
39
this._quality = Math.round(n);
40
41
if (isNodePattern(cb)) {
42
cb.call(this, null, this);
43
}
44
45
return this;
46
}
47
}
48
});
49
50