Skip to content

Commit

Permalink
Added xres, yres, update dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
vseventer committed Jul 20, 2017
1 parent a18515d commit 0705b7f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
22 changes: 20 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down Expand Up @@ -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
})
}])
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
42 changes: 42 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,48 @@ describe(`${pkg.name} <options> [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]', () => {
Expand Down

0 comments on commit 0705b7f

Please sign in to comment.