node-js-image
Advanced tools
Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "node-js-image", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Manipulate Images in Node.js", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "jest" | ||
"test": "jest", | ||
"local": "node local.js" | ||
}, | ||
@@ -9,0 +10,0 @@ "repository": { |
const fs = require('fs') | ||
const jpeg = require('jpeg-js') | ||
const proc = require('./processing') | ||
/** @typedef { number[] } Array1D One Dimensional Array */ | ||
@@ -216,13 +218,34 @@ /** @typedef { number[][] } Array2D Two Dimensional Array */ | ||
reduce() { | ||
this._processImage(proc.reduce) | ||
return this | ||
} | ||
/** | ||
* | ||
* @param {boolean} [soft=true] | ||
*/ | ||
mask (soft = true) { | ||
if(soft) { | ||
this.grayscale() | ||
} else { | ||
this.blackwhite() | ||
} | ||
this.reduce() | ||
return this | ||
} | ||
blackwhite () { | ||
/** @param {Array1D} data */ | ||
const fn = data => data.map(px => Math.round(px / 255) === 1 ? 255 : 0) | ||
this._processImage(fn) | ||
this._processImage(proc.blackwhite) | ||
return this | ||
} | ||
grayscale () { | ||
this._processImage(proc.grayscale) | ||
return this | ||
} | ||
invert () { | ||
/** @param {Array1D} data */ | ||
const fn = data => data.map(px => Math.abs(px - 255)) | ||
this._processImage(fn) | ||
this._processImage(proc.invert) | ||
return this | ||
@@ -331,2 +354,3 @@ } | ||
this.shape = initValues.shape | ||
this.isFlat = true | ||
} | ||
@@ -333,0 +357,0 @@ return this |
12369
8
408