UNPKG

imagemagick-async

Version:
158 lines (136 loc) 3.09 kB
let Path = require('path'); let PathParts = __dirname.split(Path.sep); let index = PathParts.indexOf('imagemagick-async'); let RootDir = PathParts.slice(0, index + 1).join(Path.sep); let Err = require(Path.join(RootDir, 'error.js')); let Validate = require(Path.join(RootDir, 'validate.js')); let Filepath = require(Path.join(RootDir, 'filepath.js')).Filepath; let ResizeBaseClass = require(Path.join(Filepath.TransformResizeDir(), 'resizebaseclass.js')).ResizeBaseClass; //----------------------------------- class ResizeDimensions extends ResizeBaseClass { constructor(builder) { super(builder); } /** * @override */ static get Builder() { class Builder { constructor() { this.name = 'ResizeDimensions'; this.args = {}; } /** * @param {string} str */ source(str) { this.args.source = str; return this; } /** * @param {number} n */ width(n) { this.args.width = n; return this; } /** * @param {number} n */ height(n) { this.args.height = n; return this; } build() { return new ResizeDimensions(this); } } return new Builder(); } /** * @override */ Args() { return ['-resize', `${this.args.width}x${this.args.height}!`]; } /** * @override */ Errors() { let params = Crop.Parameters(); let errors = []; let prefix = 'CROP_RESIZE_TRANSFORM_ERROR'; let sourceErr = Err.ErrorMessage.Builder .prefix(prefix) .varName('Source') .condition( new Err.StringCondition.Builder(this.args.source) .isempty(false) .isWhitespace(false) .build() ) .build() .String(); if (sourceErr) errors.push(sourceErr); let widthErr = Err.ErrorMessage.Builder .prefix(prefix) .varName('Width') .condition( new Err.NumberCondition.Builder(this.args.width) .isInteger(true) .min(params.width.min) .build() ) .build() .String(); if (widthErr) errors.push(widthErr); let heightErr = Err.ErrorMessage.Builder .prefix(prefix) .varName('Height') .condition( new Err.NumberCondition.Builder(this.args.height) .isInteger(true) .min(params.height.min) .build() ) .build() .String(); if (heightErr) errors.push(heightErr); return errors; } /** * @override */ IsConsolidatable() { return true; } /** * @override */ static Parameters() { return { source: { type: 'string', required: true }, width: { type: 'number', subtype: 'integer', min: 1, required: true }, height: { type: 'number', subtype: 'integer', min: 1, required: true } }; } } //--------------------------- // EXPORTS exports.ResizeDimensions = ResizeDimensions;