imagemagick-async
Version:
An API for Image Magick commands.
157 lines (136 loc) • 3.13 kB
JavaScript
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 ResizeFillGivenArea extends ResizeBaseClass {
constructor(builder) {
super(builder);
}
/**
* @override
*/
static get Builder() {
class Builder {
constructor() {
this.name = 'ResizeFillGivenArea';
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 ResizeFillGivenArea(this);
}
}
return new Builder();
}
/**
* @override
*/
Args() {
return ['-resize', `${this.args.width}x${this.args.height}^`];
}
/**
* @override
*/
Errors() {
let params = ResizeFillGivenArea.Parameters();
let errors = [];
let prefix = 'RESIZE_FILL_GIVEN_AREA_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.ResizeFillGivenArea = ResizeFillGivenArea;