2
0
mirror of https://github.com/thumbsup/thumbsup synced 2024-11-11 07:10:26 +00:00
thumbsup/src/steps/actions.js
Andrew McOlash 282713f273 Allow generating rectangular thumbnails (#146)
Add rectangular thumbnail
2019-02-25 19:06:03 +01:00

45 lines
1.6 KiB
JavaScript

const downsize = require('thumbsup-downsize')
const fs = require('fs-extra')
exports.createMap = function (opts) {
const thumbSize = opts.thumbSize || 120
const smallSize = 300
const largeSize = opts.largeSize || 1000
const defaultOptions = {
quality: opts.photoQuality,
args: opts.gmArgs
}
const watermark = (!opts.watermark) ? null : {
file: opts.watermark,
position: opts.watermarkPosition
}
const thumbnail = Object.assign({}, defaultOptions, {
height: thumbSize,
width: thumbSize
})
const small = Object.assign({}, defaultOptions, {
height: smallSize
})
const large = Object.assign({}, defaultOptions, {
height: largeSize,
watermark: watermark,
animated: true
})
const videoOpts = {
format: opts.videoFormat,
quality: opts.videoQuality,
bitrate: opts.videoBitrate
}
return {
'fs:copy': (task, done) => fs.copy(task.src, task.dest, done),
'fs:symlink': (task, done) => fs.symlink(task.src, task.dest, done),
'photo:thumbnail': (task, done) => downsize.image(task.src, task.dest, thumbnail, done),
'photo:small': (task, done) => downsize.image(task.src, task.dest, small, done),
'photo:large': (task, done) => downsize.image(task.src, task.dest, large, done),
'video:thumbnail': (task, done) => downsize.still(task.src, task.dest, thumbnail, done),
'video:small': (task, done) => downsize.still(task.src, task.dest, small, done),
'video:poster': (task, done) => downsize.still(task.src, task.dest, large, done),
'video:resized': (task, done) => downsize.video(task.src, task.dest, videoOpts, done)
}
}