Path: blob/master/node_modules/@jimp/jpeg/src/index.js
1126 views
import JPEG from 'jpeg-js';1import { throwError, isNodePattern } from '@jimp/utils';23const MIME_TYPE = 'image/jpeg';45export default () => ({6mime: { [MIME_TYPE]: ['jpeg', 'jpg', 'jpe'] },78constants: {9MIME_JPEG: MIME_TYPE10},1112decoders: {13[MIME_TYPE]: JPEG.decode14},1516encoders: {17[MIME_TYPE]: image => JPEG.encode(image.bitmap, image._quality).data18},1920class: {21// The quality to be used when saving JPEG images22_quality: 100,23/**24* Sets the quality of the image when saving as JPEG format (default is 100)25* @param {number} n The quality to use 0-10026* @param {function(Error, Jimp)} cb (optional) a callback for when complete27* @returns {Jimp} this for chaining of methods28*/29quality(n, cb) {30if (typeof n !== 'number') {31return throwError.call(this, 'n must be a number', cb);32}3334if (n < 0 || n > 100) {35return throwError.call(this, 'n must be a number 0 - 100', cb);36}3738this._quality = Math.round(n);3940if (isNodePattern(cb)) {41cb.call(this, null, this);42}4344return this;45}46}47});484950