From 0705b7f681964350bd629240e5261160f87bf942 Mon Sep 17 00:00:00 2001 From: vseventer Date: Thu, 20 Jul 2017 20:46:06 +0100 Subject: [PATCH] Added xres, yres, update dependencies. --- CHANGELOG.md | 7 +++++++ README.md | 2 ++ lib/cli.js | 22 ++++++++++++++++++++-- package.json | 6 +++--- test/cli.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c8746e..08615c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 1.5.0 (July 20, 2017) +> https://github.com/vseventer/sharp-cli/compare/v1.4.0...v1.5.0 + +* Added [`--xres`](http://sharp.dimens.io/en/stable/api-output/#tiff) and + [`--yres`](http://sharp.dimens.io/en/stable/api-output/#tiff) (`sharp` 0.18.2). +* Updated `fs-extra` dependency. + ## 1.4.0 (June 26, 2017) > https://github.com/vseventer/sharp-cli/compare/v1.3.0...v1.4.0 diff --git a/README.md b/README.md index d8fe739..119ffd1 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,8 @@ Optimization Options VIPS_ACCESS_SEQUENTIAL [boolean] --squash Squash 8-bit images down to 1 bit [boolean] --trellisQuantisation Apply trellis quantisation [boolean] + --xres Horizontal resolution [number] [default: 1.0] + --yres Vertical resolution [number] [default: 1.0] Misc. Options --help, -h Show help [boolean] diff --git a/lib/cli.js b/lib/cli.js index c9b1a99..26e7b88 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -229,6 +229,22 @@ const options = { desc: 'Apply trellis quantisation', group: optimize, type: 'boolean' + }, + + // @see http://sharp.dimens.io/en/stable/api-output/#tiff + xres: { + defaultDescription: '1.0', + desc: 'Horizontal resolution', + group: optimize, + type: 'number' + }, + + // @see http://sharp.dimens.io/en/stable/api-output/#tiff + yres: { + defaultDescription: '1.0', + desc: 'Vertical resolution', + group: optimize, + type: 'number' } } @@ -346,14 +362,16 @@ cli.parse = (argv, context, callback) => { // @see http://sharp.dimens.io/en/stable/api-output/#tiff if (args.compression !== options.compression.default || args.predictor !== options.predictor.default || - args.quality || args.squash) { + args.quality || args.squash || args.xres || args.yres) { queue.unshift([ 'tiff', (sharp) => { return sharp.tiff({ compression: args.compression, force: false, predictor: args.predictor, quality: args.quality, - squash: args.squash + squash: args.squash, + xres: args.xres, + yres: args.yres }) }]) } diff --git a/package.json b/package.json index 9cd1410..c08400d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "sharp-cli", - "version" : "1.4.0", + "version" : "1.5.0", "description" : "CLI for sharp.", "keywords" : [ "cli", "jpeg", "libvips", "png", "sharp", "vips", "webp" ], "homepage" : "https://github.com/vseventer/sharp-cli", @@ -18,12 +18,12 @@ "dependencies": { "bubble-stream-error": "1.0.x", "multiyargs" : "1.0.x", - "sharp" : "0.18.1", + "sharp" : "0.18.2", "url-template" : "2.0.x", "yargs" : "8.0.x" }, "devDependencies": { - "fs-extra" : "3.0.x", + "fs-extra" : "4.0.x", "mocha" : "3.4.x", "must" : "0.13.x", "nyc" : "11.0.x", diff --git a/test/cli.js b/test/cli.js index e42b425..1223663 100644 --- a/test/cli.js +++ b/test/cli.js @@ -515,6 +515,48 @@ describe(`${pkg.name} [command..]`, () => { }) }) }) + + describe('--xres', () => { + // Default horizontal resolution. + const xRes = '1.5' + + // Run. + beforeEach((done) => cli.parse([ '--xres', xRes, ...ioFlags ], done)) + + // Tests. + it('must set the xres flag', () => { + expect(cli.parsed.argv).to.have.property('xres', parseFloat(xRes)) + }) + it('must update the pipeline', () => { + expect(queue.pipeline).to.have.length(1) + expect(queue.pipeline).to.include('tiff') + }) + it('must execute the pipeline', () => { + const pipeline = queue.drain(sharp()) + sinon.assert.calledWithMatch(pipeline.tiff, { xres: parseFloat(xRes) }) + }) + }) + + describe('--yres', () => { + // Default vertical resolution. + const yRes = '1.5' + + // Run. + beforeEach((done) => cli.parse([ '--yres', yRes, ...ioFlags ], done)) + + // Tests. + it('must set the yres flag', () => { + expect(cli.parsed.argv).to.have.property('yres', parseFloat(yRes)) + }) + it('must update the pipeline', () => { + expect(queue.pipeline).to.have.length(1) + expect(queue.pipeline).to.include('tiff') + }) + it('must execute the pipeline', () => { + const pipeline = queue.drain(sharp()) + sinon.assert.calledWithMatch(pipeline.tiff, { yres: parseFloat(yRes) }) + }) + }) }) describe('[command]', () => {