diff --git a/package.json b/package.json index cb4a38e..afa5274 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,8 @@ "lodash": "^4.17.4", "winston": "^2.3.1", "squirrel": "^1.0.0", - "url-pattern": "^1.0.3" + "url-pattern": "^1.0.3", + "sharp": "^0.18.4" }, "pluginDependencies": { "imagemin": "^3.2.2", diff --git a/src/options.js b/src/options.js index 84a8727..1839928 100644 --- a/src/options.js +++ b/src/options.js @@ -23,6 +23,8 @@ function createSchema() { quality: joi.number().min(0).max(1), width: joi.number().integer().min(1), height: joi.number().integer().min(1), + resizeWidth: joi.number().integer().min(1), + resizeHeight: joi.number().integer().min(1), paperFormat: joi.string().trim().valid( 'letter', 'A2', 'A3', 'A4', 'A5'), paperOrientation: joi.string().lowercase().trim().valid( diff --git a/src/scripts/screenshot.js b/src/scripts/screenshot.js index c1c18e9..aac62cf 100644 --- a/src/scripts/screenshot.js +++ b/src/scripts/screenshot.js @@ -6,6 +6,7 @@ var system = require('system'), webpage = require('webpage'), + sharp = require('sharp'), fs = require('fs'); var DEF_ZOOM = 1, @@ -213,6 +214,11 @@ }; page.render(outputFile, renderOptions); + + if (options.resizeWidth || options.resizeHeight) { + log('Resize to ' + options.resizeWidth + 'x' + options.resizeHeight + 'px'); + sharp(outputFile).resize(options.resizeWidth, options.resizeHeight).toFile(outputFile); + } } log('Captured file: ' + outputFile);