mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 15:25:07 +01:00
Upgrade to libvips 8.10.6-alpha1
- Prebuilt binaries now include mozjpeg and libimagequant (BSD 2-Clause) - Prebuilt binaries limit AVIF support to the most common 8-bit depth - Add `mozjpeg` option to `jpeg` method, sets mozjpeg defaults - Reduce the default PNG `compressionLevel` to the more commonly used 6
This commit is contained in:
@@ -244,7 +244,7 @@ const Sharp = function (input, options) {
|
||||
jpegOptimiseCoding: true,
|
||||
jpegQuantisationTable: 0,
|
||||
pngProgressive: false,
|
||||
pngCompressionLevel: 9,
|
||||
pngCompressionLevel: 6,
|
||||
pngAdaptiveFiltering: false,
|
||||
pngPalette: false,
|
||||
pngQuality: 100,
|
||||
|
||||
@@ -198,8 +198,6 @@ function toFormat (format, options) {
|
||||
/**
|
||||
* Use these JPEG options for output image.
|
||||
*
|
||||
* Some of these options require the use of a globally-installed libvips compiled with support for mozjpeg.
|
||||
*
|
||||
* @example
|
||||
* // Convert any input to very high quality JPEG output
|
||||
* const data = await sharp(input)
|
||||
@@ -209,18 +207,25 @@ function toFormat (format, options) {
|
||||
* })
|
||||
* .toBuffer();
|
||||
*
|
||||
* @example
|
||||
* // Use mozjpeg to reduce output JPEG file size (slower)
|
||||
* const data = await sharp(input)
|
||||
* .jpeg({ mozjpeg: true })
|
||||
* .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 otherwise defaults to '4:2:0' chroma subsampling
|
||||
* @param {boolean} [options.optimiseCoding=true] - optimise Huffman coding tables
|
||||
* @param {boolean} [options.optimizeCoding=true] - alternative spelling of optimiseCoding
|
||||
* @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, requires libvips compiled with support for mozjpeg
|
||||
* @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, requires libvips compiled with support for mozjpeg
|
||||
* @param {boolean} [options.mozjpeg=false] - use mozjpeg defaults, equivalent to `{ trellisQuantisation: true, overshootDeringing: true, optimiseScans: true, quantisationTable: 3 }`
|
||||
* @param {boolean} [options.trellisQuantisation=false] - apply trellis quantisation
|
||||
* @param {boolean} [options.overshootDeringing=false] - apply overshoot deringing
|
||||
* @param {boolean} [options.optimiseScans=false] - optimise progressive scans, forces progressive
|
||||
* @param {boolean} [options.optimizeScans=false] - alternative spelling of optimiseScans
|
||||
* @param {number} [options.quantisationTable=0] - quantization table to use, integer 0-8
|
||||
* @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
|
||||
@@ -244,6 +249,23 @@ function jpeg (options) {
|
||||
throw is.invalidParameterError('chromaSubsampling', 'one of: 4:2:0, 4:4:4', options.chromaSubsampling);
|
||||
}
|
||||
}
|
||||
const optimiseCoding = is.bool(options.optimizeCoding) ? options.optimizeCoding : options.optimiseCoding;
|
||||
if (is.defined(optimiseCoding)) {
|
||||
this._setBooleanOption('jpegOptimiseCoding', optimiseCoding);
|
||||
}
|
||||
if (is.defined(options.mozjpeg)) {
|
||||
if (is.bool(options.mozjpeg)) {
|
||||
if (options.mozjpeg) {
|
||||
this.options.jpegTrellisQuantisation = true;
|
||||
this.options.jpegOvershootDeringing = true;
|
||||
this.options.jpegOptimiseScans = true;
|
||||
this.options.jpegProgressive = true;
|
||||
this.options.jpegQuantisationTable = 3;
|
||||
}
|
||||
} else {
|
||||
throw is.invalidParameterError('mozjpeg', 'boolean', options.mozjpeg);
|
||||
}
|
||||
}
|
||||
const trellisQuantisation = is.bool(options.trellisQuantization) ? options.trellisQuantization : options.trellisQuantisation;
|
||||
if (is.defined(trellisQuantisation)) {
|
||||
this._setBooleanOption('jpegTrellisQuantisation', trellisQuantisation);
|
||||
@@ -258,10 +280,6 @@ function jpeg (options) {
|
||||
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)) {
|
||||
@@ -277,26 +295,31 @@ function jpeg (options) {
|
||||
/**
|
||||
* Use these PNG options for output image.
|
||||
*
|
||||
* PNG output is always full colour at 8 or 16 bits per pixel.
|
||||
* By default, PNG output is full colour at 8 or 16 bits per pixel.
|
||||
* Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
|
||||
*
|
||||
* Some of these options require the use of a globally-installed libvips compiled with support for libimagequant (GPL).
|
||||
* Set `palette` to `true` for slower, indexed PNG output.
|
||||
*
|
||||
* @example
|
||||
* // Convert any input to PNG output
|
||||
* // Convert any input to full colour PNG output
|
||||
* const data = await sharp(input)
|
||||
* .png()
|
||||
* .toBuffer();
|
||||
*
|
||||
* @example
|
||||
* // Convert any input to indexed PNG output (slower)
|
||||
* const data = await sharp(input)
|
||||
* .png({ palette: true })
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {Object} [options]
|
||||
* @param {boolean} [options.progressive=false] - use progressive (interlace) scan
|
||||
* @param {number} [options.compressionLevel=9] - zlib compression level, 0-9
|
||||
* @param {number} [options.compressionLevel=6] - zlib compression level, 0 (fastest, largest) to 9 (slowest, smallest)
|
||||
* @param {boolean} [options.adaptiveFiltering=false] - use adaptive row filtering
|
||||
* @param {boolean} [options.palette=false] - quantise to a palette-based image with alpha transparency support, requires libvips compiled with support for libimagequant
|
||||
* @param {number} [options.quality=100] - use the lowest number of colours needed to achieve given quality, sets `palette` to `true`, requires libvips compiled with support for libimagequant
|
||||
* @param {number} [options.colours=256] - maximum number of palette entries, sets `palette` to `true`, requires libvips compiled with support for libimagequant
|
||||
* @param {number} [options.colors=256] - alternative spelling of `options.colours`, sets `palette` to `true`, requires libvips compiled with support for libimagequant
|
||||
* @param {number} [options.dither=1.0] - level of Floyd-Steinberg error diffusion, sets `palette` to `true`, requires libvips compiled with support for libimagequant
|
||||
* @param {boolean} [options.palette=false] - quantise to a palette-based image with alpha transparency support
|
||||
* @param {number} [options.quality=100] - use the lowest number of colours needed to achieve given quality, sets `palette` to `true`
|
||||
* @param {number} [options.colours=256] - maximum number of palette entries, sets `palette` to `true`
|
||||
* @param {number} [options.colors=256] - alternative spelling of `options.colours`, sets `palette` to `true`
|
||||
* @param {number} [options.dither=1.0] - level of Floyd-Steinberg error diffusion, sets `palette` to `true`
|
||||
* @param {boolean} [options.force=true] - force PNG output, otherwise attempt to use input format
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid options
|
||||
|
||||
Reference in New Issue
Block a user