imagemagick-async
Version:
An API for Image Magick commands.
130 lines (111 loc) • 2.64 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 ColorBaseClass = require(Path.join(Filepath.ModColorDir(), 'colorbaseclass.js')).ColorBaseClass;
//------------------------------
class Hue extends ColorBaseClass {
constructor(builder) {
super(builder);
}
/**
* @override
*/
static get Builder() {
class Builder {
constructor() {
this.name = 'Hue';
this.args = {};
}
/**
* @param {string} str The path of the image file you are modifying.
*/
source(str) {
this.args.source = str;
return this;
}
/**
* @param {number} n Hue value between 0 and 200. A value of 100 will make no changes.
*/
value(n) {
this.args.value = n;
return this;
}
build() {
return new Hue(this);
}
}
return new Builder();
}
/**
* @returns {Array<string|number>} Returns an array of image magick arguments associated with this layer.
*/
Args() {
return ['-modulate', `100,100,${this.args.value}`];
}
/**
* @override
*/
Errors() {
let params = Hue.Parameters();
let errors = [];
let prefix = 'HUE_COLOR_MOD_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 valueErr = Err.ErrorMessage.Builder
.prefix(prefix)
.varName('Value')
.condition(
new Err.NumberCondition.Builder(this.args.value)
.isInteger(true)
.min(params.value.min)
.max(params.value.max)
.build()
)
.build()
.String();
if (sourceErr)
errors.push(sourceErr);
return errors;
}
/**
* @override
*/
IsConsolidatable() {
return true;
}
/**
* @override
*/
static Parameters() {
return {
source: {
type: 'string',
required: true
},
value: {
type: 'number',
min: 0,
max: 200,
required: true
}
};
}
}
//---------------------------
// EXPORTS
exports.Hue = Hue;