feat(core): new --gm-args flag to pass additional options to GraphicsMagick

Example: thumbsup --gm-args ‘modulate 120’ --gm-args ‘equalize’
Closes #89.
pull/107/head
Romain 6 years ago
parent dd282f92d4
commit 3c946621ec

@ -68,10 +68,16 @@ const OPTIONS = {
'default': false
},
'concurrency': {
group: 'Output options:',
description: 'Number of parallel parsing/processing operations',
type: 'number',
'default': os.cpus().length
},
'gm-args': {
group: 'Output options:',
description: 'Custom image processing arguments for GraphicsMagick',
type: 'array'
},
// ------------------------------------
// Album options
@ -229,6 +235,12 @@ exports.get = (args) => {
replaceInArray(opts['albums-from'], 'folders', '%path')
replaceInArray(opts['albums-from'], 'date', `{${opts['albums-date-format']}}`)
// Add a dash prefix to any --gm-args value
// We can't specify the prefix on the CLI otherwise the parser thinks it's a thumbsup arg
if (opts['gm-args']) {
opts['gm-args'] = opts['gm-args'].map(val => `-${val}`)
}
// All options as an object
return {
input: opts['input'],
@ -256,7 +268,8 @@ exports.get = (args) => {
usageStats: opts['usage-stats'],
log: opts['log'],
dryRun: opts['dry-run'],
concurrency: opts['concurrency']
concurrency: opts['concurrency'],
gmArgs: opts['gm-args']
}
}

@ -89,10 +89,14 @@ function modifiedDate (filepath) {
}
function getActionMap (opts) {
const defaultOptions = {
quality: opts.photoQuality,
args: opts.gmArgs
}
const thumbSize = opts.thumbSize || 120
const largeSize = opts.largeSize || 1000
const thumbnail = { height: thumbSize, width: thumbSize, quality: opts.photoQuality }
const large = { height: largeSize, quality: opts.photoQuality }
const thumbnail = Object.assign({}, defaultOptions, {height: thumbSize, width: thumbSize})
const large = Object.assign({}, defaultOptions, {height: largeSize})
return {
'fs:copy': (task, done) => fs.copy(task.src, task.dest, done),
'fs:symlink': (task, done) => fs.symlink(task.src, task.dest, done),

@ -28,6 +28,27 @@ describe('options', function () {
should(opts.albumsFrom).eql(['%path', '%keywords'])
})
})
describe('--gm-args', () => {
it('is optional', () => {
const opts = options.get(BASE_ARGS)
should(opts.gmArgs).undefined()
})
it('prefixes with the required dash', () => {
// we don't use the dash on the command line to avoid ambiguity
// i.e. so the parser doesn't think "-modulate" is a thumbsup argument
const args = BASE_ARGS.concat(['--gm-args', 'modulate 120'])
const opts = options.get(args)
should(opts.gmArgs).eql(['-modulate 120'])
})
it('can be specified multiple times', () => {
const args = BASE_ARGS.concat([
'--gm-args', 'equalize',
'--gm-args', 'modulate 120'
])
const opts = options.get(args)
should(opts.gmArgs).eql(['-equalize', '-modulate 120'])
})
})
describe('deprecated', () => {
it('--original-photos false', () => {
const args = BASE_ARGS.concat(['--original-photos false'])

Loading…
Cancel
Save