lib/output.js
function jpeg (options) {
  if (is.object(options)) {
    if (is.defined(options.quality)) {
      if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
        this.options.jpegQuality = options.quality;
      } else {
        throw new Error('Invalid quality (integer, 1-100) ' + options.quality);
      }
    }
    if (is.defined(options.progressive)) {
      this._setBooleanOption('jpegProgressive', options.progressive);
    }
    if (is.defined(options.chromaSubsampling)) {
      if (is.string(options.chromaSubsampling) && is.inArray(options.chromaSubsampling, ['4:2:0', '4:4:4'])) {
        this.options.jpegChromaSubsampling = options.chromaSubsampling;
      } else {
        throw new Error('Invalid chromaSubsampling (4:2:0, 4:4:4) ' + options.chromaSubsampling);
      }
    }
    const trellisQuantisation = is.bool(options.trellisQuantization) ? options.trellisQuantization : options.trellisQuantisation;
    if (is.defined(trellisQuantisation)) {
      this._setBooleanOption('jpegTrellisQuantisation', trellisQuantisation);
    }
    if (is.defined(options.overshootDeringing)) {
      this._setBooleanOption('jpegOvershootDeringing', options.overshootDeringing);
    }
    const optimiseScans = is.bool(options.optimizeScans) ? options.optimizeScans : options.optimiseScans;
    if (is.defined(optimiseScans)) {
      this._setBooleanOption('jpegOptimiseScans', optimiseScans);
      if (optimiseScans) {
        this.options.jpegProgressive = true;
      }
    }
    const optimiseCoding = is.bool(options.optimizeCoding) ? options.optimizeCoding : options.optimiseCoding;
    if (is.defined(optimiseCoding)) {
      this._setBooleanOption('jpegOptimiseCoding', optimiseCoding);
    }
    const quantisationTable = is.number(options.quantizationTable) ? options.quantizationTable : options.quantisationTable;
    if (is.defined(quantisationTable)) {
      if (is.integer(quantisationTable) && is.inRange(quantisationTable, 0, 8)) {
        this.options.jpegQuantisationTable = quantisationTable;
      } else {
        throw new Error('Invalid quantisation table (integer, 0-8) ' + quantisationTable);
      }
    }
  }
  return this._updateFormatOut('jpeg', options);
}
function jpeg (options) {
  if (is.object(options)) {
    if (is.defined(options.quality)) {
      if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
        this.options.jpegQuality = options.quality;
      } else {
        throw new Error('Invalid quality (integer, 1-100) ' + options.quality);
      }
    }
    if (is.defined(options.progressive)) {
      this._setBooleanOption('jpegProgressive', options.progressive);
    }
    if (is.defined(options.chromaSubsampling)) {
      if (is.string(options.chromaSubsampling) && is.inArray(options.chromaSubsampling, ['4:2:0', '4:4:4'])) {
        this.options.jpegChromaSubsampling = options.chromaSubsampling;
      } else {
        throw new Error('Invalid chromaSubsampling (4:2:0, 4:4:4) ' + options.chromaSubsampling);
      }
    }
    const trellisQuantisation = is.bool(options.trellisQuantization) ? options.trellisQuantization : options.trellisQuantisation;
    if (is.defined(trellisQuantisation)) {
      this._setBooleanOption('jpegTrellisQuantisation', trellisQuantisation);
    }
    if (is.defined(options.overshootDeringing)) {
      this._setBooleanOption('jpegOvershootDeringing', options.overshootDeringing);
    }
    const optimiseScans = is.bool(options.optimizeScans) ? options.optimizeScans : options.optimiseScans;
    if (is.defined(optimiseScans)) {
      this._setBooleanOption('jpegOptimiseScans', optimiseScans);
      if (optimiseScans) {
        this.options.jpegProgressive = true;
      }
    }
    const optimiseCoding = is.bool(options.optimizeCoding) ? options.optimizeCoding : options.optimiseCoding;
    if (is.defined(optimiseCoding)) {
      this._setBooleanOption('jpegOptimiseCoding', optimiseCoding);
    }
    const quantisationTable = is.number(options.quantizationTable) ? options.quantizationTable : options.quantisationTable;
    if (is.defined(quantisationTable)) {
      if (is.integer(quantisationTable) && is.inRange(quantisationTable, 0, 8)) {
        this.options.jpegQuantisationTable = quantisationTable;
      } else {
        throw new Error('Invalid quantisation table (integer, 0-8) ' + quantisationTable);
      }
    }
  }
  return this._updateFormatOut('jpeg', options);
}
function jpeg ( options ) { if ( is . object ( options ) ) { if ( is . defined ( options . quality ) ) { if ( is . integer ( options . quality ) && is . inRange ( options . quality , 1 , 100 ) ) { this . options . jpegQuality = options . quality ; } else { throw new Error ( 'Invalid quality (integer, 1-100) ' + options . quality ) ; } } if ( is . defined ( options . progressive ) ) { this . _setBooleanOption ( 'jpegProgressive' , options . progressive ) ; } if ( is . defined ( options . chromaSubsampling ) ) { if ( is . string ( options . chromaSubsampling ) && is . inArray ( options . chromaSubsampling , [ '4:2:0' , '4:4:4' ] ) ) { this . options . jpegChromaSubsampling = options . chromaSubsampling ; } else { throw new Error ( 'Invalid chromaSubsampling (4:2:0, 4:4:4) ' + options . chromaSubsampling ) ; } } const trellisQuantisation = is . bool ( options . trellisQuantization ) ? options . trellisQuantization : options . trellisQuantisation ; if ( is . defined ( trellisQuantisation ) ) { this . _setBooleanOption ( 'jpegTrellisQuantisation' , trellisQuantisation ) ; } if ( is . defined ( options . overshootDeringing ) ) { this . _setBooleanOption ( 'jpegOvershootDeringing' , options . overshootDeringing ) ; } const optimiseScans = is . bool ( options . optimizeScans ) ? options . optimizeScans : options . optimiseScans ; if ( is . defined ( optimiseScans ) ) { this . _setBooleanOption ( 'jpegOptimiseScans' , optimiseScans ) ; if ( optimiseScans ) { this . options . jpegProgressive = true ; } } const optimiseCoding = is . bool ( options . optimizeCoding ) ? options . optimizeCoding : options . optimiseCoding ; if ( is . defined ( optimiseCoding ) ) { this . _setBooleanOption ( 'jpegOptimiseCoding' , optimiseCoding ) ; } const quantisationTable = is . number ( options . quantizationTable ) ? options . quantizationTable : options . quantisationTable ; if ( is . defined ( quantisationTable ) ) { if ( is . integer ( quantisationTable ) && is . inRange ( quantisationTable , 0 , 8 ) ) { this . options . jpegQuantisationTable = quantisationTable ; } else { throw new Error ( 'Invalid quantisation table (integer, 0-8) ' + quantisationTable ) ; } } } return this . _updateFormatOut ( 'jpeg' , options ) ; }
Use these JPEG options for output image.

@example
// Convert any input to very high quality JPEG output
const data = await sharp(input)
.jpeg({
quality: 100,
chromaSubsampling: '4:4:4'
})
.toBuffer();

@param {Object} [options] - output options
@param {Number} [options.quality=80] - quality, integer 1-100
@param {Boolean} [options.progressive=false] - use progressive (interlace) scan
@param {String} [options.chromaSubsampling='4:2:0'] - set to '4:4:4' to prevent chroma subsampling when quality <= 90
@param {Boolean} [options.trellisQuantisation=false] - apply trellis quantisation, requires libvips compiled with support for mozjpeg
@param {Boolean} [options.overshootDeringing=false] - apply overshoot deringing, requires libvips compiled with support for mozjpeg
@param {Boolean} [options.optimiseScans=false] - optimise progressive scans, forces progressive, requires libvips compiled with support for mozjpeg
@param {Boolean} [options.optimizeScans=false] - alternative spelling of optimiseScans
@param {Boolean} [options.optimiseCoding=true] - optimise Huffman coding tables
@param {Boolean} [options.optimizeCoding=true] - alternative spelling of optimiseCoding
@param {Number} [options.quantisationTable=0] - quantization table to use, integer 0-8, requires libvips compiled with support for mozjpeg
@param {Number} [options.quantizationTable=0] - alternative spelling of quantisationTable
@param {Boolean} [options.force=true] - force JPEG output, otherwise attempt to use input format
@returns {Sharp}
@throws {Error} Invalid options
Use these JPEG options for output image .