UNPKG

imagemagick-async

Version:
152 lines (131 loc) 3.06 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 Filepath = require(Path.join(RootDir, 'filepath.js')).Filepath; let CanvasBaseClass = require(Path.join(Filepath.CanvasDir(), 'canvasbaseclass.js')).CanvasBaseClass; //---------------------------------------- // COLOR CANVAS class ColorCanvas extends CanvasBaseClass { constructor(builder) { super(builder); } /** * @override */ static get Builder() { class Builder { constructor() { this.name = 'ColorCanvas'; this.args = {}; this.primitives = []; } /** * @param {number} n Width in pixels. */ width(n) { this.args.width = n; return this; } /** * @param {number} n Height in pixels. */ height(n) { this.args.height = n; return this; } /** * @param {Color} color */ color(color) { this.args.color = color; return this; } build() { return new ColorCanvas(this); } } return new Builder(); } /** * @override */ Args() { return ['-size', `${this.args.width}x${this.args.height}`, `canvas:${this.args.color.String()}`]; } /** * @override */ Errors() { let params = ColorCanvas.Parameters(); let errors = []; let prefix = 'COLOR_CANVAS_ERROR'; // Check required args 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); let colorErr = Err.ErrorMessage.Builder .prefix(prefix) .varName('Color') .condition( new Err.ObjectCondition.Builder(this.args.color) .typeName('Color') .checkForErrors(true) .build() ) .build() .String(); if (colorErr) errors.push(colorErr); } /** * @override */ static Parameters() { return { width: { type: 'number', subtype: 'integer', min: 1, required: true }, height: { type: 'number', subtype: 'integer', min: 1, required: true }, color: { type: 'Inputs.Color', required: true } }; } } //----------------------------- // EXPORTS exports.ColorCanvas = ColorCanvas;