From dd9d66ef20a059e7da705f78146af2f33509d31b Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Sun, 13 Nov 2016 20:46:08 +0000 Subject: [PATCH] Update output docs to include tile image format. Correct some of the JPEG output option type defs. --- docs/api-output.md | 12 +++++++----- docs/changelog.md | 4 ++++ lib/output.js | 12 +++++++----- lib/types.d.ts | 14 ++++++++------ test/unit/tile.js | 12 ++++++------ 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/docs/api-output.md b/docs/api-output.md index 903e54ce..6a0973b4 100644 --- a/docs/api-output.md +++ b/docs/api-output.md @@ -64,11 +64,11 @@ Use these JPEG options for output image. - `options.quality` **\[[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)]** quality, integer 1-100 (optional, default `80`) - `options.progressive` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** use progressive (interlace) scan (optional, default `false`) - `options.chromaSubsampling` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** set to '4:4:4' to prevent chroma subsampling when quality <= 90 (optional, default `'4:2:0'`) + - `options.trellisQuantisation` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** apply trellis quantisation, requires mozjpeg (optional, default `false`) + - `options.overshootDeringing` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** apply overshoot deringing, requires mozjpeg (optional, default `false`) + - `options.optimiseScans` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** optimise progressive scans, forces progressive, requires mozjpeg (optional, default `false`) + - `options.optimizeScans` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** alternative spelling of optimiseScans (optional, default `false`) - `options.force` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** force JPEG output, otherwise attempt to use input format (optional, default `true`) -- `trellisQuantisation` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** apply trellis quantisation, requires mozjpeg (optional, default `false`) -- `overshootDeringing` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** apply overshoot deringing, requires mozjpeg (optional, default `false`) -- `optimiseScans` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** optimise progressive scans, forces progressive, requires mozjpeg (optional, default `false`) -- `optimizeScans` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** alternative spelling of optimiseScans (optional, default `false`) - Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid options @@ -145,7 +145,8 @@ Returns **Sharp** # tile Use tile-based deep zoom (image pyramid) output. -You can also use a `.zip` or `.szi` file extension with `toFile` to write to a compressed archive file format. +Set the format and options for tile images via the `toFormat`, `jpeg`, `png` or `webp` functions. +Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed archive file format. **Parameters** @@ -159,6 +160,7 @@ You can also use a `.zip` or `.szi` file extension with `toFile` to write to a c ```javascript sharp('input.tiff') + .png() .tile({ size: 512 }) diff --git a/docs/changelog.md b/docs/changelog.md index d0c9dcb1..bc4b436c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -26,6 +26,10 @@ Requires libvips v8.4.2. [#601](https://github.com/lovell/sharp/issues/601) [@dynamite-ready](https://github.com/dynamite-ready) +* Add support for PNG and WebP tile-based output formats (in addition to JPEG). + [#622](https://github.com/lovell/sharp/pull/622) + [@ppaskaris](https://github.com/ppaskaris) + ### v0.16 - "*pencil*" Requires libvips v8.3.3 diff --git a/lib/output.js b/lib/output.js index 2048cf8f..c8a91ede 100644 --- a/lib/output.js +++ b/lib/output.js @@ -88,10 +88,10 @@ const withMetadata = function withMetadata (withMetadata) { * @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} [trellisQuantisation=false] - apply trellis quantisation, requires mozjpeg - * @param {Boolean} [overshootDeringing=false] - apply overshoot deringing, requires mozjpeg - * @param {Boolean} [optimiseScans=false] - optimise progressive scans, forces progressive, requires mozjpeg - * @param {Boolean} [optimizeScans=false] - alternative spelling of optimiseScans + * @param {Boolean} [options.trellisQuantisation=false] - apply trellis quantisation, requires mozjpeg + * @param {Boolean} [options.overshootDeringing=false] - apply overshoot deringing, requires mozjpeg + * @param {Boolean} [options.optimiseScans=false] - optimise progressive scans, forces progressive, requires mozjpeg + * @param {Boolean} [options.optimizeScans=false] - alternative spelling of optimiseScans * @param {Boolean} [options.force=true] - force JPEG output, otherwise attempt to use input format * @returns {Sharp} * @throws {Error} Invalid options @@ -227,10 +227,12 @@ const toFormat = function toFormat (format, options) { /** * Use tile-based deep zoom (image pyramid) output. - * You can also use a `.zip` or `.szi` file extension with `toFile` to write to a compressed archive file format. + * Set the format and options for tile images via the `toFormat`, `jpeg`, `png` or `webp` functions. + * Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed archive file format. * * @example * sharp('input.tiff') + * .png() * .tile({ * size: 512 * }) diff --git a/lib/types.d.ts b/lib/types.d.ts index 1b92659d..c4a5cf9f 100644 --- a/lib/types.d.ts +++ b/lib/types.d.ts @@ -770,15 +770,15 @@ declare function withMetadata(withMetadata?: { orientation: Number }): Sharp; * @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} [trellisQuantisation=false] - apply trellis quantisation, requires mozjpeg - * @param {Boolean} [overshootDeringing=false] - apply overshoot deringing, requires mozjpeg - * @param {Boolean} [optimiseScans=false] - optimise progressive scans, forces progressive, requires mozjpeg - * @param {Boolean} [optimizeScans=false] - alternative spelling of optimiseScans + * @param {Boolean} [options.trellisQuantisation=false] - apply trellis quantisation, requires mozjpeg + * @param {Boolean} [options.overshootDeringing=false] - apply overshoot deringing, requires mozjpeg + * @param {Boolean} [options.optimiseScans=false] - optimise progressive scans, forces progressive, requires mozjpeg + * @param {Boolean} [options.optimizeScans=false] - alternative spelling of optimiseScans * @param {Boolean} [options.force=true] - force JPEG output, otherwise attempt to use input format * @returns {Sharp} * @throws {Error} Invalid options */ -declare function jpeg(options?: { quality: Number, progressive: Boolean, chromaSubsampling: String, force: Boolean }, trellisQuantisation?: Boolean, overshootDeringing?: Boolean, optimiseScans?: Boolean, optimizeScans?: Boolean): Sharp; +declare function jpeg(options?: { quality: Number, progressive: Boolean, chromaSubsampling: String, trellisQuantisation: Boolean, overshootDeringing: Boolean, optimiseScans: Boolean, optimizeScans: Boolean, force: Boolean }): Sharp; /** * Use these PNG options for output image. @@ -829,10 +829,12 @@ declare function toFormat(format: (String|Object), options: Object): Sharp; /** * Use tile-based deep zoom (image pyramid) output. - * You can also use a `.zip` or `.szi` file extension with `toFile` to write to a compressed archive file format. + * Set the format and options for tile images via the `toFormat`, `jpeg`, `png` or `webp` functions. + * Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed archive file format. * * @example * sharp('input.tiff') + * .png() * .tile({ * size: 512 * }) diff --git a/test/unit/tile.js b/test/unit/tile.js index 6d34cf52..c829ce08 100644 --- a/test/unit/tile.js +++ b/test/unit/tile.js @@ -263,8 +263,8 @@ describe('Tile', function () { assert.strictEqual(3, metadata.channels); assert.strictEqual(false, metadata.hasProfile); assert.strictEqual(false, metadata.hasAlpha); - assert.strictEqual(true, metadata.width === 256); - assert.strictEqual(true, metadata.height === 256); + assert.strictEqual(256, metadata.width); + assert.strictEqual(256, metadata.height); fs.stat(sample, function (err, stat) { if (err) throw err; assert.strictEqual(true, stat.size < 2000); @@ -298,8 +298,8 @@ describe('Tile', function () { assert.strictEqual(3, metadata.channels); assert.strictEqual(false, metadata.hasProfile); assert.strictEqual(false, metadata.hasAlpha); - assert.strictEqual(true, metadata.width === 256); - assert.strictEqual(true, metadata.height === 256); + assert.strictEqual(256, metadata.width); + assert.strictEqual(256, metadata.height); fs.stat(sample, function (err, stat) { if (err) throw err; assert.strictEqual(true, stat.size > 44000); @@ -333,8 +333,8 @@ describe('Tile', function () { assert.strictEqual(3, metadata.channels); assert.strictEqual(false, metadata.hasProfile); assert.strictEqual(false, metadata.hasAlpha); - assert.strictEqual(true, metadata.width === 256); - assert.strictEqual(true, metadata.height === 256); + assert.strictEqual(256, metadata.width); + assert.strictEqual(256, metadata.height); fs.stat(sample, function (err, stat) { if (err) throw err; assert.strictEqual(true, stat.size < 2000);