mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Improve multi-frame image resizing (#2789)
* Ports vips_thumbnail logic to sharp * Deprecates the pageHeight output option for WebP/GIF
This commit is contained in:
committed by
GitHub
parent
659cdabd8e
commit
513fb40f40
@@ -458,9 +458,8 @@ function png (options) {
|
||||
* @param {boolean} [options.nearLossless=false] - use near_lossless compression mode
|
||||
* @param {boolean} [options.smartSubsample=false] - use high quality chroma subsampling
|
||||
* @param {number} [options.effort=4] - CPU effort, between 0 (fastest) and 6 (slowest)
|
||||
* @param {number} [options.pageHeight] - page height for animated output
|
||||
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
|
||||
* @param {number[]} [options.delay] - list of delays between animation frames (in milliseconds)
|
||||
* @param {number|number[]} [options.delay] - delay(s) between animation frames (in milliseconds)
|
||||
* @param {boolean} [options.force=true] - force WebP output, otherwise attempt to use input format
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid options
|
||||
@@ -527,10 +526,7 @@ function webp (options) {
|
||||
* width: 128,
|
||||
* height: 128 * pages
|
||||
* })
|
||||
* .gif({
|
||||
* pageHeight: 128,
|
||||
* dither: 0
|
||||
* })
|
||||
* .gif({ dither: 0 })
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {Object} [options] - output options
|
||||
@@ -538,9 +534,8 @@ function webp (options) {
|
||||
* @param {number} [options.colors=256] - alternative spelling of `options.colours`
|
||||
* @param {number} [options.effort=7] - CPU effort, between 1 (fastest) and 10 (slowest)
|
||||
* @param {number} [options.dither=1.0] - level of Floyd-Steinberg error diffusion, between 0 (least) and 1 (most)
|
||||
* @param {number} [options.pageHeight] - page height for animated output
|
||||
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
|
||||
* @param {number[]} [options.delay] - list of delays between animation frames (in milliseconds)
|
||||
* @param {number|number[]} [options.delay] - delay(s) between animation frames (in milliseconds)
|
||||
* @param {boolean} [options.force=true] - force GIF output, otherwise attempt to use input format
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid options
|
||||
@@ -657,20 +652,12 @@ function jp2 (options) {
|
||||
* @private
|
||||
*
|
||||
* @param {Object} [source] - output options
|
||||
* @param {number} [source.pageHeight] - page height for animated output
|
||||
* @param {number} [source.loop=0] - number of animation iterations, use 0 for infinite animation
|
||||
* @param {number[]} [source.delay] - list of delays between animation frames (in milliseconds)
|
||||
* @param {Object} [target] - target object for valid options
|
||||
* @throws {Error} Invalid options
|
||||
*/
|
||||
function trySetAnimationOptions (source, target) {
|
||||
if (is.object(source) && is.defined(source.pageHeight)) {
|
||||
if (is.integer(source.pageHeight) && source.pageHeight > 0) {
|
||||
target.pageHeight = source.pageHeight;
|
||||
} else {
|
||||
throw is.invalidParameterError('pageHeight', 'integer larger than 0', source.pageHeight);
|
||||
}
|
||||
}
|
||||
if (is.object(source) && is.defined(source.loop)) {
|
||||
if (is.integer(source.loop) && is.inRange(source.loop, 0, 65535)) {
|
||||
target.loop = source.loop;
|
||||
@@ -679,13 +666,16 @@ function trySetAnimationOptions (source, target) {
|
||||
}
|
||||
}
|
||||
if (is.object(source) && is.defined(source.delay)) {
|
||||
if (
|
||||
// We allow singular values as well
|
||||
if (is.integer(source.delay) && is.inRange(source.delay, 0, 65535)) {
|
||||
target.delay = [source.delay];
|
||||
} else if (
|
||||
Array.isArray(source.delay) &&
|
||||
source.delay.every(is.integer) &&
|
||||
source.delay.every(v => is.inRange(v, 0, 65535))) {
|
||||
target.delay = source.delay;
|
||||
} else {
|
||||
throw is.invalidParameterError('delay', 'array of integers between 0 and 65535', source.delay);
|
||||
throw is.invalidParameterError('delay', 'integer or an array of integers between 0 and 65535', source.delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user