WIP - add extractor, generate snippet_data
This commit is contained in:
21
node_modules/@jimp/plugin-crop/LICENSE
generated
vendored
Normal file
21
node_modules/@jimp/plugin-crop/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Oliver Moran
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
56
node_modules/@jimp/plugin-crop/README.md
generated
vendored
Normal file
56
node_modules/@jimp/plugin-crop/README.md
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
<div align="center">
|
||||
<img width="200" height="200"
|
||||
src="https://s3.amazonaws.com/pix.iemoji.com/images/emoji/apple/ios-11/256/crayon.png">
|
||||
<h1>@jimp/plugin-crop</h1>
|
||||
<p>Crop an image.</p>
|
||||
</div>
|
||||
|
||||
## Crop
|
||||
|
||||
Crops the image at a given point to a give size
|
||||
|
||||
- @param {number} x the x coordinate to crop form
|
||||
- @param {number} y the y coordinate to crop form
|
||||
- @param w the width of the crop region
|
||||
- @param h the height of the crop region
|
||||
- @param {function(Error, Jimp)} cb (optional) a callback for when complete
|
||||
|
||||
```js
|
||||
import jimp from 'jimp';
|
||||
|
||||
async function main() {
|
||||
const image = await jimp.read('test/image.png');
|
||||
|
||||
image.crop(150, 150);
|
||||
}
|
||||
|
||||
main();
|
||||
```
|
||||
|
||||
## AutoCrop
|
||||
|
||||
AutoCrop same color borders from this image
|
||||
|
||||
- @param {number} tolerance (optional): a percent value of tolerance for pixels color difference (default: 0.0002%)
|
||||
- @param {boolean} cropOnlyFrames (optional): flag to crop only real frames: all 4 sides of the image must have some border (default: true)
|
||||
|
||||
or
|
||||
|
||||
- @param {object} options object
|
||||
- tolerance (optional): a percent value of tolerance for pixels color difference (default: 0.0002%)
|
||||
- cropOnlyFrames (optional): flag to crop only real frames: all 4 sides of the image must have some border (default: true)
|
||||
- cropSymmetric (optional): flag to force cropping top be symmetric. north and south / east and west are cropped by the same value
|
||||
- leaveBorder (optional): integer of how many pixels of the background color to leave around the image
|
||||
|
||||
```js
|
||||
import jimp from 'jimp';
|
||||
|
||||
async function main() {
|
||||
const image = await jimp.read('test/image.png');
|
||||
|
||||
image.autocrop();
|
||||
image.autocrop({ cropOnlyFrames: false, cropSymmetric: true });
|
||||
}
|
||||
|
||||
main();
|
||||
```
|
||||
268
node_modules/@jimp/plugin-crop/dist/index.js
generated
vendored
Normal file
268
node_modules/@jimp/plugin-crop/dist/index.js
generated
vendored
Normal file
@ -0,0 +1,268 @@
|
||||
"use strict";
|
||||
|
||||
require("core-js/modules/es6.object.define-property");
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = pluginCrop;
|
||||
|
||||
require("core-js/modules/es7.symbol.async-iterator");
|
||||
|
||||
require("core-js/modules/es6.symbol");
|
||||
|
||||
var _utils = require("@jimp/utils");
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function pluginCrop(event) {
|
||||
/**
|
||||
* Crops the image at a given point to a give size
|
||||
* @param {number} x the x coordinate to crop form
|
||||
* @param {number} y the y coordinate to crop form
|
||||
* @param w the width of the crop region
|
||||
* @param h the height of the crop region
|
||||
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
|
||||
* @returns {Jimp} this for chaining of methods
|
||||
*/
|
||||
event('crop', function (x, y, w, h, cb) {
|
||||
if (typeof x !== 'number' || typeof y !== 'number') return _utils.throwError.call(this, 'x and y must be numbers', cb);
|
||||
if (typeof w !== 'number' || typeof h !== 'number') return _utils.throwError.call(this, 'w and h must be numbers', cb); // round input
|
||||
|
||||
x = Math.round(x);
|
||||
y = Math.round(y);
|
||||
w = Math.round(w);
|
||||
h = Math.round(h);
|
||||
|
||||
if (x === 0 && w === this.bitmap.width) {
|
||||
// shortcut
|
||||
var start = w * y + x << 2;
|
||||
var end = start + h * w << 2 + 1;
|
||||
this.bitmap.data = this.bitmap.data.slice(start, end);
|
||||
} else {
|
||||
var bitmap = Buffer.allocUnsafe(w * h * 4);
|
||||
var offset = 0;
|
||||
this.scanQuiet(x, y, w, h, function (x, y, idx) {
|
||||
var data = this.bitmap.data.readUInt32BE(idx, true);
|
||||
bitmap.writeUInt32BE(data, offset, true);
|
||||
offset += 4;
|
||||
});
|
||||
this.bitmap.data = bitmap;
|
||||
}
|
||||
|
||||
this.bitmap.width = w;
|
||||
this.bitmap.height = h;
|
||||
|
||||
if ((0, _utils.isNodePattern)(cb)) {
|
||||
cb.call(this, null, this);
|
||||
}
|
||||
|
||||
return this;
|
||||
});
|
||||
return {
|
||||
class: {
|
||||
/**
|
||||
* Autocrop same color borders from this image
|
||||
* @param {number} tolerance (optional): a percent value of tolerance for pixels color difference (default: 0.0002%)
|
||||
* @param {boolean} cropOnlyFrames (optional): flag to crop only real frames: all 4 sides of the image must have some border (default: true)
|
||||
* @param {function(Error, Jimp)} cb (optional): a callback for when complete (default: no callback)
|
||||
* @returns {Jimp} this for chaining of methods
|
||||
*/
|
||||
autocrop: function autocrop() {
|
||||
var w = this.bitmap.width;
|
||||
var h = this.bitmap.height;
|
||||
var minPixelsPerSide = 1; // to avoid cropping completely the image, resulting in an invalid 0 sized image
|
||||
|
||||
var cb; // callback
|
||||
|
||||
var leaveBorder = 0; // Amount of pixels in border to leave
|
||||
|
||||
var tolerance = 0.0002; // percent of color difference tolerance (default value)
|
||||
|
||||
var cropOnlyFrames = true; // flag to force cropping only if the image has a real "frame"
|
||||
// i.e. all 4 sides have some border (default value)
|
||||
|
||||
var cropSymmetric = false; // flag to force cropping top be symmetric.
|
||||
// i.e. north and south / east and west are cropped by the same value
|
||||
// parse arguments
|
||||
|
||||
for (var a = 0, len = arguments.length; a < len; a++) {
|
||||
if (typeof (a < 0 || arguments.length <= a ? undefined : arguments[a]) === 'number') {
|
||||
// tolerance value passed
|
||||
tolerance = a < 0 || arguments.length <= a ? undefined : arguments[a];
|
||||
}
|
||||
|
||||
if (typeof (a < 0 || arguments.length <= a ? undefined : arguments[a]) === 'boolean') {
|
||||
// cropOnlyFrames value passed
|
||||
cropOnlyFrames = a < 0 || arguments.length <= a ? undefined : arguments[a];
|
||||
}
|
||||
|
||||
if (typeof (a < 0 || arguments.length <= a ? undefined : arguments[a]) === 'function') {
|
||||
// callback value passed
|
||||
cb = a < 0 || arguments.length <= a ? undefined : arguments[a];
|
||||
}
|
||||
|
||||
if (_typeof(a < 0 || arguments.length <= a ? undefined : arguments[a]) === 'object') {
|
||||
// config object passed
|
||||
var config = a < 0 || arguments.length <= a ? undefined : arguments[a];
|
||||
|
||||
if (typeof config.tolerance !== 'undefined') {
|
||||
tolerance = config.tolerance;
|
||||
}
|
||||
|
||||
if (typeof config.cropOnlyFrames !== 'undefined') {
|
||||
cropOnlyFrames = config.cropOnlyFrames;
|
||||
}
|
||||
|
||||
if (typeof config.cropSymmetric !== 'undefined') {
|
||||
cropSymmetric = config.cropSymmetric;
|
||||
}
|
||||
|
||||
if (typeof config.leaveBorder !== 'undefined') {
|
||||
leaveBorder = config.leaveBorder;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* All borders must be of the same color as the top left pixel, to be cropped.
|
||||
* It should be possible to crop borders each with a different color,
|
||||
* but since there are many ways for corners to intersect, it would
|
||||
* introduce unnecessary complexity to the algorithm.
|
||||
*/
|
||||
// scan each side for same color borders
|
||||
|
||||
|
||||
var colorTarget = this.getPixelColor(0, 0); // top left pixel color is the target color
|
||||
|
||||
var rgba1 = this.constructor.intToRGBA(colorTarget); // for north and east sides
|
||||
|
||||
var northPixelsToCrop = 0;
|
||||
var eastPixelsToCrop = 0;
|
||||
var southPixelsToCrop = 0;
|
||||
var westPixelsToCrop = 0; // north side (scan rows from north to south)
|
||||
|
||||
colorTarget = this.getPixelColor(0, 0);
|
||||
|
||||
north: for (var y = 0; y < h - minPixelsPerSide; y++) {
|
||||
for (var x = 0; x < w; x++) {
|
||||
var colorXY = this.getPixelColor(x, y);
|
||||
var rgba2 = this.constructor.intToRGBA(colorXY);
|
||||
|
||||
if (this.constructor.colorDiff(rgba1, rgba2) > tolerance) {
|
||||
// this pixel is too distant from the first one: abort this side scan
|
||||
break north;
|
||||
}
|
||||
} // this row contains all pixels with the same color: increment this side pixels to crop
|
||||
|
||||
|
||||
northPixelsToCrop++;
|
||||
} // east side (scan columns from east to west)
|
||||
|
||||
|
||||
colorTarget = this.getPixelColor(w, 0);
|
||||
|
||||
east: for (var _x = 0; _x < w - minPixelsPerSide; _x++) {
|
||||
for (var _y = 0 + northPixelsToCrop; _y < h; _y++) {
|
||||
var _colorXY = this.getPixelColor(_x, _y);
|
||||
|
||||
var _rgba = this.constructor.intToRGBA(_colorXY);
|
||||
|
||||
if (this.constructor.colorDiff(rgba1, _rgba) > tolerance) {
|
||||
// this pixel is too distant from the first one: abort this side scan
|
||||
break east;
|
||||
}
|
||||
} // this column contains all pixels with the same color: increment this side pixels to crop
|
||||
|
||||
|
||||
eastPixelsToCrop++;
|
||||
} // south side (scan rows from south to north)
|
||||
|
||||
|
||||
colorTarget = this.getPixelColor(0, h);
|
||||
|
||||
south: for (var _y2 = h - 1; _y2 >= northPixelsToCrop + minPixelsPerSide; _y2--) {
|
||||
for (var _x2 = w - eastPixelsToCrop - 1; _x2 >= 0; _x2--) {
|
||||
var _colorXY2 = this.getPixelColor(_x2, _y2);
|
||||
|
||||
var _rgba2 = this.constructor.intToRGBA(_colorXY2);
|
||||
|
||||
if (this.constructor.colorDiff(rgba1, _rgba2) > tolerance) {
|
||||
// this pixel is too distant from the first one: abort this side scan
|
||||
break south;
|
||||
}
|
||||
} // this row contains all pixels with the same color: increment this side pixels to crop
|
||||
|
||||
|
||||
southPixelsToCrop++;
|
||||
} // west side (scan columns from west to east)
|
||||
|
||||
|
||||
colorTarget = this.getPixelColor(w, h);
|
||||
|
||||
west: for (var _x3 = w - 1; _x3 >= 0 + eastPixelsToCrop + minPixelsPerSide; _x3--) {
|
||||
for (var _y3 = h - 1; _y3 >= 0 + northPixelsToCrop; _y3--) {
|
||||
var _colorXY3 = this.getPixelColor(_x3, _y3);
|
||||
|
||||
var _rgba3 = this.constructor.intToRGBA(_colorXY3);
|
||||
|
||||
if (this.constructor.colorDiff(rgba1, _rgba3) > tolerance) {
|
||||
// this pixel is too distant from the first one: abort this side scan
|
||||
break west;
|
||||
}
|
||||
} // this column contains all pixels with the same color: increment this side pixels to crop
|
||||
|
||||
|
||||
westPixelsToCrop++;
|
||||
} // decide if a crop is needed
|
||||
|
||||
|
||||
var doCrop = false; // apply leaveBorder
|
||||
|
||||
westPixelsToCrop = westPixelsToCrop - leaveBorder;
|
||||
eastPixelsToCrop = eastPixelsToCrop - leaveBorder;
|
||||
northPixelsToCrop = northPixelsToCrop - leaveBorder;
|
||||
southPixelsToCrop = southPixelsToCrop - leaveBorder;
|
||||
|
||||
if (cropSymmetric) {
|
||||
var horizontal = Math.min(eastPixelsToCrop, westPixelsToCrop);
|
||||
var vertical = Math.min(northPixelsToCrop, southPixelsToCrop);
|
||||
westPixelsToCrop = horizontal;
|
||||
eastPixelsToCrop = horizontal;
|
||||
northPixelsToCrop = vertical;
|
||||
southPixelsToCrop = vertical;
|
||||
} // safety checks
|
||||
|
||||
|
||||
var widthOfRemainingPixels = w - (westPixelsToCrop + eastPixelsToCrop);
|
||||
var heightOfRemainingPixels = h - (southPixelsToCrop + northPixelsToCrop); // make sure that crops are > 0
|
||||
|
||||
westPixelsToCrop = westPixelsToCrop >= 0 ? westPixelsToCrop : 0;
|
||||
eastPixelsToCrop = eastPixelsToCrop >= 0 ? eastPixelsToCrop : 0;
|
||||
northPixelsToCrop = northPixelsToCrop >= 0 ? northPixelsToCrop : 0;
|
||||
southPixelsToCrop = southPixelsToCrop >= 0 ? southPixelsToCrop : 0;
|
||||
|
||||
if (cropOnlyFrames) {
|
||||
// crop image if all sides should be cropped
|
||||
doCrop = eastPixelsToCrop !== 0 && northPixelsToCrop !== 0 && westPixelsToCrop !== 0 && southPixelsToCrop !== 0;
|
||||
} else {
|
||||
// crop image if at least one side should be cropped
|
||||
doCrop = eastPixelsToCrop !== 0 || northPixelsToCrop !== 0 || westPixelsToCrop !== 0 || southPixelsToCrop !== 0;
|
||||
}
|
||||
|
||||
if (doCrop) {
|
||||
// do the real crop
|
||||
this.crop(eastPixelsToCrop, northPixelsToCrop, widthOfRemainingPixels, heightOfRemainingPixels);
|
||||
}
|
||||
|
||||
if ((0, _utils.isNodePattern)(cb)) {
|
||||
cb.call(this, null, this);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@jimp/plugin-crop/dist/index.js.map
generated
vendored
Normal file
1
node_modules/@jimp/plugin-crop/dist/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
253
node_modules/@jimp/plugin-crop/es/index.js
generated
vendored
Normal file
253
node_modules/@jimp/plugin-crop/es/index.js
generated
vendored
Normal file
@ -0,0 +1,253 @@
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
/* eslint-disable no-labels */
|
||||
import { throwError, isNodePattern } from '@jimp/utils';
|
||||
export default function pluginCrop(event) {
|
||||
/**
|
||||
* Crops the image at a given point to a give size
|
||||
* @param {number} x the x coordinate to crop form
|
||||
* @param {number} y the y coordinate to crop form
|
||||
* @param w the width of the crop region
|
||||
* @param h the height of the crop region
|
||||
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
|
||||
* @returns {Jimp} this for chaining of methods
|
||||
*/
|
||||
event('crop', function (x, y, w, h, cb) {
|
||||
if (typeof x !== 'number' || typeof y !== 'number') return throwError.call(this, 'x and y must be numbers', cb);
|
||||
if (typeof w !== 'number' || typeof h !== 'number') return throwError.call(this, 'w and h must be numbers', cb); // round input
|
||||
|
||||
x = Math.round(x);
|
||||
y = Math.round(y);
|
||||
w = Math.round(w);
|
||||
h = Math.round(h);
|
||||
|
||||
if (x === 0 && w === this.bitmap.width) {
|
||||
// shortcut
|
||||
var start = w * y + x << 2;
|
||||
var end = start + h * w << 2 + 1;
|
||||
this.bitmap.data = this.bitmap.data.slice(start, end);
|
||||
} else {
|
||||
var bitmap = Buffer.allocUnsafe(w * h * 4);
|
||||
var offset = 0;
|
||||
this.scanQuiet(x, y, w, h, function (x, y, idx) {
|
||||
var data = this.bitmap.data.readUInt32BE(idx, true);
|
||||
bitmap.writeUInt32BE(data, offset, true);
|
||||
offset += 4;
|
||||
});
|
||||
this.bitmap.data = bitmap;
|
||||
}
|
||||
|
||||
this.bitmap.width = w;
|
||||
this.bitmap.height = h;
|
||||
|
||||
if (isNodePattern(cb)) {
|
||||
cb.call(this, null, this);
|
||||
}
|
||||
|
||||
return this;
|
||||
});
|
||||
return {
|
||||
class: {
|
||||
/**
|
||||
* Autocrop same color borders from this image
|
||||
* @param {number} tolerance (optional): a percent value of tolerance for pixels color difference (default: 0.0002%)
|
||||
* @param {boolean} cropOnlyFrames (optional): flag to crop only real frames: all 4 sides of the image must have some border (default: true)
|
||||
* @param {function(Error, Jimp)} cb (optional): a callback for when complete (default: no callback)
|
||||
* @returns {Jimp} this for chaining of methods
|
||||
*/
|
||||
autocrop: function autocrop() {
|
||||
var w = this.bitmap.width;
|
||||
var h = this.bitmap.height;
|
||||
var minPixelsPerSide = 1; // to avoid cropping completely the image, resulting in an invalid 0 sized image
|
||||
|
||||
var cb; // callback
|
||||
|
||||
var leaveBorder = 0; // Amount of pixels in border to leave
|
||||
|
||||
var tolerance = 0.0002; // percent of color difference tolerance (default value)
|
||||
|
||||
var cropOnlyFrames = true; // flag to force cropping only if the image has a real "frame"
|
||||
// i.e. all 4 sides have some border (default value)
|
||||
|
||||
var cropSymmetric = false; // flag to force cropping top be symmetric.
|
||||
// i.e. north and south / east and west are cropped by the same value
|
||||
// parse arguments
|
||||
|
||||
for (var a = 0, len = arguments.length; a < len; a++) {
|
||||
if (typeof (a < 0 || arguments.length <= a ? undefined : arguments[a]) === 'number') {
|
||||
// tolerance value passed
|
||||
tolerance = a < 0 || arguments.length <= a ? undefined : arguments[a];
|
||||
}
|
||||
|
||||
if (typeof (a < 0 || arguments.length <= a ? undefined : arguments[a]) === 'boolean') {
|
||||
// cropOnlyFrames value passed
|
||||
cropOnlyFrames = a < 0 || arguments.length <= a ? undefined : arguments[a];
|
||||
}
|
||||
|
||||
if (typeof (a < 0 || arguments.length <= a ? undefined : arguments[a]) === 'function') {
|
||||
// callback value passed
|
||||
cb = a < 0 || arguments.length <= a ? undefined : arguments[a];
|
||||
}
|
||||
|
||||
if (_typeof(a < 0 || arguments.length <= a ? undefined : arguments[a]) === 'object') {
|
||||
// config object passed
|
||||
var config = a < 0 || arguments.length <= a ? undefined : arguments[a];
|
||||
|
||||
if (typeof config.tolerance !== 'undefined') {
|
||||
tolerance = config.tolerance;
|
||||
}
|
||||
|
||||
if (typeof config.cropOnlyFrames !== 'undefined') {
|
||||
cropOnlyFrames = config.cropOnlyFrames;
|
||||
}
|
||||
|
||||
if (typeof config.cropSymmetric !== 'undefined') {
|
||||
cropSymmetric = config.cropSymmetric;
|
||||
}
|
||||
|
||||
if (typeof config.leaveBorder !== 'undefined') {
|
||||
leaveBorder = config.leaveBorder;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* All borders must be of the same color as the top left pixel, to be cropped.
|
||||
* It should be possible to crop borders each with a different color,
|
||||
* but since there are many ways for corners to intersect, it would
|
||||
* introduce unnecessary complexity to the algorithm.
|
||||
*/
|
||||
// scan each side for same color borders
|
||||
|
||||
|
||||
var colorTarget = this.getPixelColor(0, 0); // top left pixel color is the target color
|
||||
|
||||
var rgba1 = this.constructor.intToRGBA(colorTarget); // for north and east sides
|
||||
|
||||
var northPixelsToCrop = 0;
|
||||
var eastPixelsToCrop = 0;
|
||||
var southPixelsToCrop = 0;
|
||||
var westPixelsToCrop = 0; // north side (scan rows from north to south)
|
||||
|
||||
colorTarget = this.getPixelColor(0, 0);
|
||||
|
||||
north: for (var y = 0; y < h - minPixelsPerSide; y++) {
|
||||
for (var x = 0; x < w; x++) {
|
||||
var colorXY = this.getPixelColor(x, y);
|
||||
var rgba2 = this.constructor.intToRGBA(colorXY);
|
||||
|
||||
if (this.constructor.colorDiff(rgba1, rgba2) > tolerance) {
|
||||
// this pixel is too distant from the first one: abort this side scan
|
||||
break north;
|
||||
}
|
||||
} // this row contains all pixels with the same color: increment this side pixels to crop
|
||||
|
||||
|
||||
northPixelsToCrop++;
|
||||
} // east side (scan columns from east to west)
|
||||
|
||||
|
||||
colorTarget = this.getPixelColor(w, 0);
|
||||
|
||||
east: for (var _x = 0; _x < w - minPixelsPerSide; _x++) {
|
||||
for (var _y = 0 + northPixelsToCrop; _y < h; _y++) {
|
||||
var _colorXY = this.getPixelColor(_x, _y);
|
||||
|
||||
var _rgba = this.constructor.intToRGBA(_colorXY);
|
||||
|
||||
if (this.constructor.colorDiff(rgba1, _rgba) > tolerance) {
|
||||
// this pixel is too distant from the first one: abort this side scan
|
||||
break east;
|
||||
}
|
||||
} // this column contains all pixels with the same color: increment this side pixels to crop
|
||||
|
||||
|
||||
eastPixelsToCrop++;
|
||||
} // south side (scan rows from south to north)
|
||||
|
||||
|
||||
colorTarget = this.getPixelColor(0, h);
|
||||
|
||||
south: for (var _y2 = h - 1; _y2 >= northPixelsToCrop + minPixelsPerSide; _y2--) {
|
||||
for (var _x2 = w - eastPixelsToCrop - 1; _x2 >= 0; _x2--) {
|
||||
var _colorXY2 = this.getPixelColor(_x2, _y2);
|
||||
|
||||
var _rgba2 = this.constructor.intToRGBA(_colorXY2);
|
||||
|
||||
if (this.constructor.colorDiff(rgba1, _rgba2) > tolerance) {
|
||||
// this pixel is too distant from the first one: abort this side scan
|
||||
break south;
|
||||
}
|
||||
} // this row contains all pixels with the same color: increment this side pixels to crop
|
||||
|
||||
|
||||
southPixelsToCrop++;
|
||||
} // west side (scan columns from west to east)
|
||||
|
||||
|
||||
colorTarget = this.getPixelColor(w, h);
|
||||
|
||||
west: for (var _x3 = w - 1; _x3 >= 0 + eastPixelsToCrop + minPixelsPerSide; _x3--) {
|
||||
for (var _y3 = h - 1; _y3 >= 0 + northPixelsToCrop; _y3--) {
|
||||
var _colorXY3 = this.getPixelColor(_x3, _y3);
|
||||
|
||||
var _rgba3 = this.constructor.intToRGBA(_colorXY3);
|
||||
|
||||
if (this.constructor.colorDiff(rgba1, _rgba3) > tolerance) {
|
||||
// this pixel is too distant from the first one: abort this side scan
|
||||
break west;
|
||||
}
|
||||
} // this column contains all pixels with the same color: increment this side pixels to crop
|
||||
|
||||
|
||||
westPixelsToCrop++;
|
||||
} // decide if a crop is needed
|
||||
|
||||
|
||||
var doCrop = false; // apply leaveBorder
|
||||
|
||||
westPixelsToCrop = westPixelsToCrop - leaveBorder;
|
||||
eastPixelsToCrop = eastPixelsToCrop - leaveBorder;
|
||||
northPixelsToCrop = northPixelsToCrop - leaveBorder;
|
||||
southPixelsToCrop = southPixelsToCrop - leaveBorder;
|
||||
|
||||
if (cropSymmetric) {
|
||||
var horizontal = Math.min(eastPixelsToCrop, westPixelsToCrop);
|
||||
var vertical = Math.min(northPixelsToCrop, southPixelsToCrop);
|
||||
westPixelsToCrop = horizontal;
|
||||
eastPixelsToCrop = horizontal;
|
||||
northPixelsToCrop = vertical;
|
||||
southPixelsToCrop = vertical;
|
||||
} // safety checks
|
||||
|
||||
|
||||
var widthOfRemainingPixels = w - (westPixelsToCrop + eastPixelsToCrop);
|
||||
var heightOfRemainingPixels = h - (southPixelsToCrop + northPixelsToCrop); // make sure that crops are > 0
|
||||
|
||||
westPixelsToCrop = westPixelsToCrop >= 0 ? westPixelsToCrop : 0;
|
||||
eastPixelsToCrop = eastPixelsToCrop >= 0 ? eastPixelsToCrop : 0;
|
||||
northPixelsToCrop = northPixelsToCrop >= 0 ? northPixelsToCrop : 0;
|
||||
southPixelsToCrop = southPixelsToCrop >= 0 ? southPixelsToCrop : 0;
|
||||
|
||||
if (cropOnlyFrames) {
|
||||
// crop image if all sides should be cropped
|
||||
doCrop = eastPixelsToCrop !== 0 && northPixelsToCrop !== 0 && westPixelsToCrop !== 0 && southPixelsToCrop !== 0;
|
||||
} else {
|
||||
// crop image if at least one side should be cropped
|
||||
doCrop = eastPixelsToCrop !== 0 || northPixelsToCrop !== 0 || westPixelsToCrop !== 0 || southPixelsToCrop !== 0;
|
||||
}
|
||||
|
||||
if (doCrop) {
|
||||
// do the real crop
|
||||
this.crop(eastPixelsToCrop, northPixelsToCrop, widthOfRemainingPixels, heightOfRemainingPixels);
|
||||
}
|
||||
|
||||
if (isNodePattern(cb)) {
|
||||
cb.call(this, null, this);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@jimp/plugin-crop/es/index.js.map
generated
vendored
Normal file
1
node_modules/@jimp/plugin-crop/es/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
62
node_modules/@jimp/plugin-crop/package.json
generated
vendored
Normal file
62
node_modules/@jimp/plugin-crop/package.json
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
{
|
||||
"_from": "@jimp/plugin-crop@^0.6.4",
|
||||
"_id": "@jimp/plugin-crop@0.6.4",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-w9TR+pn+GeWbznscGe2HRkPxInge0whAF3TLPWhPwBVjZChTT8dSDXsUpUlxQqvI4SfzuKp8z3/0SBqYDCzxxA==",
|
||||
"_location": "/@jimp/plugin-crop",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "@jimp/plugin-crop@^0.6.4",
|
||||
"name": "@jimp/plugin-crop",
|
||||
"escapedName": "@jimp%2fplugin-crop",
|
||||
"scope": "@jimp",
|
||||
"rawSpec": "^0.6.4",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^0.6.4"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@jimp/plugins"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/@jimp/plugin-crop/-/plugin-crop-0.6.4.tgz",
|
||||
"_shasum": "3447611790703cd7d51a0127b2cf77906711f9ec",
|
||||
"_spec": "@jimp/plugin-crop@^0.6.4",
|
||||
"_where": "/Users/stefanfejes/Projects/30-seconds-of-python-code/node_modules/@jimp/plugins",
|
||||
"author": "",
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"@jimp/utils": "^0.6.4",
|
||||
"core-js": "^2.5.7"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "crop an image.",
|
||||
"devDependencies": {
|
||||
"@jimp/custom": "^0.6.4",
|
||||
"@jimp/test-utils": "^0.6.4"
|
||||
},
|
||||
"gitHead": "7c9d3c817cade88d4a20422be10670d3c1528429",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.js",
|
||||
"module": "es/index.js",
|
||||
"name": "@jimp/plugin-crop",
|
||||
"peerDependencies": {
|
||||
"@jimp/custom": ">=0.3.5"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run build:node:production && npm run build:module",
|
||||
"build:debug": "npm run build:node:debug",
|
||||
"build:module": "cross-env BABEL_ENV=module babel src -d es --source-maps --config-file ../../babel.config.js",
|
||||
"build:node": "babel src -d dist --source-maps --config-file ../../babel.config.js",
|
||||
"build:node:debug": "cross-env BABEL_ENV=development npm run build:node",
|
||||
"build:node:production": "cross-env BABEL_ENV=production npm run build:node",
|
||||
"build:watch": "npm run build:node:debug -- -- --watch --verbose",
|
||||
"test": "cross-env BABEL_ENV=test mocha --require @babel/register",
|
||||
"test:coverage": "nyc npm run test",
|
||||
"test:watch": "npm run test -- --reporter min --watch"
|
||||
},
|
||||
"version": "0.6.4"
|
||||
}
|
||||
270
node_modules/@jimp/plugin-crop/src/index.js
generated
vendored
Normal file
270
node_modules/@jimp/plugin-crop/src/index.js
generated
vendored
Normal file
@ -0,0 +1,270 @@
|
||||
/* eslint-disable no-labels */
|
||||
|
||||
import { throwError, isNodePattern } from '@jimp/utils';
|
||||
|
||||
export default function pluginCrop(event) {
|
||||
/**
|
||||
* Crops the image at a given point to a give size
|
||||
* @param {number} x the x coordinate to crop form
|
||||
* @param {number} y the y coordinate to crop form
|
||||
* @param w the width of the crop region
|
||||
* @param h the height of the crop region
|
||||
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
|
||||
* @returns {Jimp} this for chaining of methods
|
||||
*/
|
||||
event('crop', function(x, y, w, h, cb) {
|
||||
if (typeof x !== 'number' || typeof y !== 'number')
|
||||
return throwError.call(this, 'x and y must be numbers', cb);
|
||||
if (typeof w !== 'number' || typeof h !== 'number')
|
||||
return throwError.call(this, 'w and h must be numbers', cb);
|
||||
|
||||
// round input
|
||||
x = Math.round(x);
|
||||
y = Math.round(y);
|
||||
w = Math.round(w);
|
||||
h = Math.round(h);
|
||||
|
||||
if (x === 0 && w === this.bitmap.width) {
|
||||
// shortcut
|
||||
const start = (w * y + x) << 2;
|
||||
const end = (start + h * w) << (2 + 1);
|
||||
|
||||
this.bitmap.data = this.bitmap.data.slice(start, end);
|
||||
} else {
|
||||
const bitmap = Buffer.allocUnsafe(w * h * 4);
|
||||
let offset = 0;
|
||||
|
||||
this.scanQuiet(x, y, w, h, function(x, y, idx) {
|
||||
const data = this.bitmap.data.readUInt32BE(idx, true);
|
||||
bitmap.writeUInt32BE(data, offset, true);
|
||||
offset += 4;
|
||||
});
|
||||
|
||||
this.bitmap.data = bitmap;
|
||||
}
|
||||
|
||||
this.bitmap.width = w;
|
||||
this.bitmap.height = h;
|
||||
|
||||
if (isNodePattern(cb)) {
|
||||
cb.call(this, null, this);
|
||||
}
|
||||
|
||||
return this;
|
||||
});
|
||||
|
||||
return {
|
||||
class: {
|
||||
/**
|
||||
* Autocrop same color borders from this image
|
||||
* @param {number} tolerance (optional): a percent value of tolerance for pixels color difference (default: 0.0002%)
|
||||
* @param {boolean} cropOnlyFrames (optional): flag to crop only real frames: all 4 sides of the image must have some border (default: true)
|
||||
* @param {function(Error, Jimp)} cb (optional): a callback for when complete (default: no callback)
|
||||
* @returns {Jimp} this for chaining of methods
|
||||
*/
|
||||
autocrop(...args) {
|
||||
const w = this.bitmap.width;
|
||||
const h = this.bitmap.height;
|
||||
const minPixelsPerSide = 1; // to avoid cropping completely the image, resulting in an invalid 0 sized image
|
||||
|
||||
let cb; // callback
|
||||
let leaveBorder = 0; // Amount of pixels in border to leave
|
||||
let tolerance = 0.0002; // percent of color difference tolerance (default value)
|
||||
let cropOnlyFrames = true; // flag to force cropping only if the image has a real "frame"
|
||||
// i.e. all 4 sides have some border (default value)
|
||||
let cropSymmetric = false; // flag to force cropping top be symmetric.
|
||||
// i.e. north and south / east and west are cropped by the same value
|
||||
|
||||
// parse arguments
|
||||
for (let a = 0, len = args.length; a < len; a++) {
|
||||
if (typeof args[a] === 'number') {
|
||||
// tolerance value passed
|
||||
tolerance = args[a];
|
||||
}
|
||||
|
||||
if (typeof args[a] === 'boolean') {
|
||||
// cropOnlyFrames value passed
|
||||
cropOnlyFrames = args[a];
|
||||
}
|
||||
|
||||
if (typeof args[a] === 'function') {
|
||||
// callback value passed
|
||||
cb = args[a];
|
||||
}
|
||||
|
||||
if (typeof args[a] === 'object') {
|
||||
// config object passed
|
||||
const config = args[a];
|
||||
|
||||
if (typeof config.tolerance !== 'undefined') {
|
||||
({ tolerance } = config);
|
||||
}
|
||||
|
||||
if (typeof config.cropOnlyFrames !== 'undefined') {
|
||||
({ cropOnlyFrames } = config);
|
||||
}
|
||||
|
||||
if (typeof config.cropSymmetric !== 'undefined') {
|
||||
({ cropSymmetric } = config);
|
||||
}
|
||||
|
||||
if (typeof config.leaveBorder !== 'undefined') {
|
||||
({ leaveBorder } = config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* All borders must be of the same color as the top left pixel, to be cropped.
|
||||
* It should be possible to crop borders each with a different color,
|
||||
* but since there are many ways for corners to intersect, it would
|
||||
* introduce unnecessary complexity to the algorithm.
|
||||
*/
|
||||
|
||||
// scan each side for same color borders
|
||||
let colorTarget = this.getPixelColor(0, 0); // top left pixel color is the target color
|
||||
const rgba1 = this.constructor.intToRGBA(colorTarget);
|
||||
|
||||
// for north and east sides
|
||||
let northPixelsToCrop = 0;
|
||||
let eastPixelsToCrop = 0;
|
||||
let southPixelsToCrop = 0;
|
||||
let westPixelsToCrop = 0;
|
||||
|
||||
// north side (scan rows from north to south)
|
||||
colorTarget = this.getPixelColor(0, 0);
|
||||
north: for (let y = 0; y < h - minPixelsPerSide; y++) {
|
||||
for (let x = 0; x < w; x++) {
|
||||
const colorXY = this.getPixelColor(x, y);
|
||||
const rgba2 = this.constructor.intToRGBA(colorXY);
|
||||
|
||||
if (this.constructor.colorDiff(rgba1, rgba2) > tolerance) {
|
||||
// this pixel is too distant from the first one: abort this side scan
|
||||
break north;
|
||||
}
|
||||
}
|
||||
// this row contains all pixels with the same color: increment this side pixels to crop
|
||||
northPixelsToCrop++;
|
||||
}
|
||||
|
||||
// east side (scan columns from east to west)
|
||||
colorTarget = this.getPixelColor(w, 0);
|
||||
east: for (let x = 0; x < w - minPixelsPerSide; x++) {
|
||||
for (let y = 0 + northPixelsToCrop; y < h; y++) {
|
||||
const colorXY = this.getPixelColor(x, y);
|
||||
const rgba2 = this.constructor.intToRGBA(colorXY);
|
||||
|
||||
if (this.constructor.colorDiff(rgba1, rgba2) > tolerance) {
|
||||
// this pixel is too distant from the first one: abort this side scan
|
||||
break east;
|
||||
}
|
||||
}
|
||||
// this column contains all pixels with the same color: increment this side pixels to crop
|
||||
eastPixelsToCrop++;
|
||||
}
|
||||
|
||||
// south side (scan rows from south to north)
|
||||
colorTarget = this.getPixelColor(0, h);
|
||||
south: for (
|
||||
let y = h - 1;
|
||||
y >= northPixelsToCrop + minPixelsPerSide;
|
||||
y--
|
||||
) {
|
||||
for (let x = w - eastPixelsToCrop - 1; x >= 0; x--) {
|
||||
const colorXY = this.getPixelColor(x, y);
|
||||
const rgba2 = this.constructor.intToRGBA(colorXY);
|
||||
|
||||
if (this.constructor.colorDiff(rgba1, rgba2) > tolerance) {
|
||||
// this pixel is too distant from the first one: abort this side scan
|
||||
break south;
|
||||
}
|
||||
}
|
||||
// this row contains all pixels with the same color: increment this side pixels to crop
|
||||
southPixelsToCrop++;
|
||||
}
|
||||
|
||||
// west side (scan columns from west to east)
|
||||
colorTarget = this.getPixelColor(w, h);
|
||||
west: for (
|
||||
let x = w - 1;
|
||||
x >= 0 + eastPixelsToCrop + minPixelsPerSide;
|
||||
x--
|
||||
) {
|
||||
for (let y = h - 1; y >= 0 + northPixelsToCrop; y--) {
|
||||
const colorXY = this.getPixelColor(x, y);
|
||||
const rgba2 = this.constructor.intToRGBA(colorXY);
|
||||
|
||||
if (this.constructor.colorDiff(rgba1, rgba2) > tolerance) {
|
||||
// this pixel is too distant from the first one: abort this side scan
|
||||
break west;
|
||||
}
|
||||
}
|
||||
// this column contains all pixels with the same color: increment this side pixels to crop
|
||||
westPixelsToCrop++;
|
||||
}
|
||||
|
||||
// decide if a crop is needed
|
||||
let doCrop = false;
|
||||
|
||||
// apply leaveBorder
|
||||
westPixelsToCrop = westPixelsToCrop - leaveBorder;
|
||||
eastPixelsToCrop = eastPixelsToCrop - leaveBorder;
|
||||
northPixelsToCrop = northPixelsToCrop - leaveBorder;
|
||||
southPixelsToCrop = southPixelsToCrop - leaveBorder;
|
||||
|
||||
if (cropSymmetric) {
|
||||
const horizontal = Math.min(eastPixelsToCrop, westPixelsToCrop);
|
||||
const vertical = Math.min(northPixelsToCrop, southPixelsToCrop);
|
||||
westPixelsToCrop = horizontal;
|
||||
eastPixelsToCrop = horizontal;
|
||||
northPixelsToCrop = vertical;
|
||||
southPixelsToCrop = vertical;
|
||||
}
|
||||
|
||||
// safety checks
|
||||
const widthOfRemainingPixels =
|
||||
w - (westPixelsToCrop + eastPixelsToCrop);
|
||||
const heightOfRemainingPixels =
|
||||
h - (southPixelsToCrop + northPixelsToCrop);
|
||||
|
||||
// make sure that crops are > 0
|
||||
westPixelsToCrop = westPixelsToCrop >= 0 ? westPixelsToCrop : 0;
|
||||
eastPixelsToCrop = eastPixelsToCrop >= 0 ? eastPixelsToCrop : 0;
|
||||
northPixelsToCrop = northPixelsToCrop >= 0 ? northPixelsToCrop : 0;
|
||||
southPixelsToCrop = southPixelsToCrop >= 0 ? southPixelsToCrop : 0;
|
||||
|
||||
if (cropOnlyFrames) {
|
||||
// crop image if all sides should be cropped
|
||||
doCrop =
|
||||
eastPixelsToCrop !== 0 &&
|
||||
northPixelsToCrop !== 0 &&
|
||||
westPixelsToCrop !== 0 &&
|
||||
southPixelsToCrop !== 0;
|
||||
} else {
|
||||
// crop image if at least one side should be cropped
|
||||
doCrop =
|
||||
eastPixelsToCrop !== 0 ||
|
||||
northPixelsToCrop !== 0 ||
|
||||
westPixelsToCrop !== 0 ||
|
||||
southPixelsToCrop !== 0;
|
||||
}
|
||||
|
||||
if (doCrop) {
|
||||
// do the real crop
|
||||
this.crop(
|
||||
eastPixelsToCrop,
|
||||
northPixelsToCrop,
|
||||
widthOfRemainingPixels,
|
||||
heightOfRemainingPixels
|
||||
);
|
||||
}
|
||||
|
||||
if (isNodePattern(cb)) {
|
||||
cb.call(this, null, this);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
320
node_modules/@jimp/plugin-crop/test/autocrop.test.js
generated
vendored
Normal file
320
node_modules/@jimp/plugin-crop/test/autocrop.test.js
generated
vendored
Normal file
@ -0,0 +1,320 @@
|
||||
import { Jimp, mkJGD } from '@jimp/test-utils';
|
||||
import configure from '@jimp/custom';
|
||||
|
||||
import crop from '../src';
|
||||
|
||||
const jimp = configure({ plugins: [crop] }, Jimp);
|
||||
|
||||
describe('Autocrop', () => {
|
||||
it('image with transparent surround color', async () => {
|
||||
const imgSrc = await jimp.read(
|
||||
mkJGD(
|
||||
' ',
|
||||
' ◆◆ ',
|
||||
' ◆▦▦◆ ',
|
||||
' ◆▦▦▦▦◆ ',
|
||||
' ◆▦▦◆ ',
|
||||
' ◆◆ ',
|
||||
' '
|
||||
)
|
||||
);
|
||||
|
||||
imgSrc
|
||||
.autocrop()
|
||||
.getJGDSync()
|
||||
.should.be.sameJGD(
|
||||
mkJGD(' ◆◆ ', ' ◆▦▦◆ ', '◆▦▦▦▦◆', ' ◆▦▦◆ ', ' ◆◆ ')
|
||||
);
|
||||
});
|
||||
|
||||
it('image with opaque surround color', async () => {
|
||||
const imgSrc = await jimp.read(
|
||||
mkJGD(
|
||||
'▥▥▥▥▥▥▥▥▥▥',
|
||||
'▥▥▥▥◆◆▥▥▥▥',
|
||||
'▥▥▥◆▦▦◆▥▥▥',
|
||||
'▥▥◆▦▦▦▦◆▥▥',
|
||||
'▥▥▥◆▦▦◆▥▥▥',
|
||||
'▥▥▥▥◆◆▥▥▥▥',
|
||||
'▥▥▥▥▥▥▥▥▥▥'
|
||||
)
|
||||
);
|
||||
|
||||
imgSrc
|
||||
.autocrop()
|
||||
.getJGDSync()
|
||||
.should.be.sameJGD(
|
||||
mkJGD('▥▥◆◆▥▥', '▥◆▦▦◆▥', '◆▦▦▦▦◆', '▥◆▦▦◆▥', '▥▥◆◆▥▥')
|
||||
);
|
||||
});
|
||||
|
||||
it('image with one color border', async () => {
|
||||
const imgSrc = await jimp.read(
|
||||
mkJGD(
|
||||
'▥▥▥▥▥▥▥▥▥▥▥▥',
|
||||
'▥▥▥▥▥▥▥▥▥▥▥▥',
|
||||
'▥▥ ◆◆ ▥▥',
|
||||
'▥▥ ◆▦▦◆ ▥▥',
|
||||
'▥▥ ◆▦▦▦▦◆ ▥▥',
|
||||
'▥▥ ◆▦▦◆ ▥▥',
|
||||
'▥▥ ◆◆ ▥▥',
|
||||
'▥▥▥▥▥▥▥▥▥▥▥▥',
|
||||
'▥▥▥▥▥▥▥▥▥▥▥▥'
|
||||
)
|
||||
);
|
||||
|
||||
imgSrc
|
||||
.autocrop()
|
||||
.getJGDSync()
|
||||
.should.be.sameJGD(
|
||||
mkJGD(' ◆◆ ', ' ◆▦▦◆ ', ' ◆▦▦▦▦◆ ', ' ◆▦▦◆ ', ' ◆◆ ')
|
||||
);
|
||||
});
|
||||
|
||||
it('image border with small variation', async () => {
|
||||
const imgSrc = await jimp.read(
|
||||
mkJGD(
|
||||
'323232323232',
|
||||
'232323232323',
|
||||
'32 ◆◆ 32',
|
||||
'23 ◆▦▦◆ 23',
|
||||
'32 ◆▦▦▦▦◆ 32',
|
||||
'23 ◆▦▦◆ 23',
|
||||
'32 ◆◆ 32',
|
||||
'232323232323',
|
||||
'323232323232'
|
||||
)
|
||||
);
|
||||
imgSrc
|
||||
.clone()
|
||||
.autocrop()
|
||||
.getJGDSync()
|
||||
.should.be.sameJGD(
|
||||
mkJGD(
|
||||
'323232323232',
|
||||
'232323232323',
|
||||
'32 ◆◆ 32',
|
||||
'23 ◆▦▦◆ 23',
|
||||
'32 ◆▦▦▦▦◆ 32',
|
||||
'23 ◆▦▦◆ 23',
|
||||
'32 ◆◆ 32',
|
||||
'232323232323',
|
||||
'323232323232'
|
||||
)
|
||||
);
|
||||
imgSrc
|
||||
.clone()
|
||||
.autocrop(0.005)
|
||||
.getJGDSync()
|
||||
.should.be.sameJGD(
|
||||
mkJGD(' ◆◆ ', ' ◆▦▦◆ ', ' ◆▦▦▦▦◆ ', ' ◆▦▦◆ ', ' ◆◆ ')
|
||||
);
|
||||
});
|
||||
|
||||
it('image border with small variation configured by options', async () => {
|
||||
const imgSrc = await Jimp.read(
|
||||
mkJGD(
|
||||
'323232323232',
|
||||
'232323232323',
|
||||
'32 ◆◆ 32',
|
||||
'23 ◆▦▦◆ 23',
|
||||
'32 ◆▦▦▦▦◆ 32',
|
||||
'23 ◆▦▦◆ 23',
|
||||
'32 ◆◆ 32',
|
||||
'232323232323',
|
||||
'323232323232'
|
||||
)
|
||||
);
|
||||
imgSrc
|
||||
.clone()
|
||||
.autocrop()
|
||||
.getJGDSync()
|
||||
.should.be.sameJGD(
|
||||
mkJGD(
|
||||
'323232323232',
|
||||
'232323232323',
|
||||
'32 ◆◆ 32',
|
||||
'23 ◆▦▦◆ 23',
|
||||
'32 ◆▦▦▦▦◆ 32',
|
||||
'23 ◆▦▦◆ 23',
|
||||
'32 ◆◆ 32',
|
||||
'232323232323',
|
||||
'323232323232'
|
||||
)
|
||||
);
|
||||
imgSrc
|
||||
.clone()
|
||||
.autocrop({ tolerance: 0.005 })
|
||||
.getJGDSync()
|
||||
.should.be.sameJGD(
|
||||
mkJGD(' ◆◆ ', ' ◆▦▦◆ ', ' ◆▦▦▦▦◆ ', ' ◆▦▦◆ ', ' ◆◆ ')
|
||||
);
|
||||
});
|
||||
|
||||
it('image without frame', async () => {
|
||||
const imgSrc = await Jimp.read(
|
||||
mkJGD(
|
||||
'▥▥ ◆◆ ',
|
||||
'▥▥ ◆▦▦◆ ',
|
||||
'▥▥ ◆▦▦▦▦◆ ',
|
||||
'▥▥ ◆▦▦◆ ',
|
||||
'▥▥ ◆◆ ',
|
||||
'▥▥▥▥▥▥▥▥▥▥',
|
||||
'▥▥▥▥▥▥▥▥▥▥'
|
||||
)
|
||||
);
|
||||
|
||||
imgSrc
|
||||
.autocrop(false)
|
||||
.getJGDSync()
|
||||
.should.be.sameJGD(
|
||||
mkJGD(' ◆◆ ', ' ◆▦▦◆ ', ' ◆▦▦▦▦◆ ', ' ◆▦▦◆ ', ' ◆◆ ')
|
||||
);
|
||||
});
|
||||
|
||||
it('image without frame configured by options', async () => {
|
||||
const imgSrc = await Jimp.read(
|
||||
mkJGD(
|
||||
'▥▥ ◆◆ ',
|
||||
'▥▥ ◆▦▦◆ ',
|
||||
'▥▥ ◆▦▦▦▦◆ ',
|
||||
'▥▥ ◆▦▦◆ ',
|
||||
'▥▥ ◆◆ ',
|
||||
'▥▥▥▥▥▥▥▥▥▥',
|
||||
'▥▥▥▥▥▥▥▥▥▥'
|
||||
)
|
||||
);
|
||||
|
||||
imgSrc
|
||||
.autocrop({ cropOnlyFrames: false })
|
||||
.getJGDSync()
|
||||
.should.be.sameJGD(
|
||||
mkJGD(' ◆◆ ', ' ◆▦▦◆ ', ' ◆▦▦▦▦◆ ', ' ◆▦▦◆ ', ' ◆◆ ')
|
||||
);
|
||||
});
|
||||
|
||||
it('image with symmetric border configured by options', async () => {
|
||||
const imgSrc = await Jimp.read(
|
||||
mkJGD(
|
||||
'▥▥▥▥▥▥▥▥▥▥▥▥▥▥',
|
||||
'▥▥ ◆◆ ▥▥▥▥',
|
||||
'▥▥ ◆▦▦◆ ▥▥▥▥',
|
||||
'▥▥ ◆▦▦▦▦◆ ▥▥▥▥',
|
||||
'▥▥ ◆▦▦◆ ▥▥▥▥',
|
||||
'▥▥ ◆◆ ▥▥▥▥',
|
||||
'▥▥▥▥▥▥▥▥▥▥▥▥▥▥',
|
||||
'▥▥▥▥▥▥▥▥▥▥▥▥▥▥'
|
||||
)
|
||||
);
|
||||
|
||||
imgSrc
|
||||
.autocrop({ cropSymmetric: true })
|
||||
.getJGDSync()
|
||||
.should.be.sameJGD(
|
||||
mkJGD(
|
||||
' ◆◆ ▥▥',
|
||||
' ◆▦▦◆ ▥▥',
|
||||
' ◆▦▦▦▦◆ ▥▥',
|
||||
' ◆▦▦◆ ▥▥',
|
||||
' ◆◆ ▥▥',
|
||||
'▥▥▥▥▥▥▥▥▥▥'
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('image without frame and with symmetric border configured by options', async () => {
|
||||
const imgSrc = await Jimp.read(
|
||||
mkJGD(
|
||||
'▥▥ ◆◆ ▥▥▥▥',
|
||||
'▥▥ ◆▦▦◆ ▥▥▥▥',
|
||||
'▥▥ ◆▦▦▦▦◆ ▥▥▥▥',
|
||||
'▥▥ ◆▦▦◆ ▥▥▥▥',
|
||||
'▥▥ ◆◆ ▥▥▥▥',
|
||||
'▥▥▥▥▥▥▥▥▥▥▥▥▥▥',
|
||||
'▥▥▥▥▥▥▥▥▥▥▥▥▥▥'
|
||||
)
|
||||
);
|
||||
imgSrc
|
||||
.autocrop({ cropSymmetric: true, cropOnlyFrames: false })
|
||||
.getJGDSync()
|
||||
.should.be.sameJGD(
|
||||
mkJGD(
|
||||
' ◆◆ ▥▥',
|
||||
' ◆▦▦◆ ▥▥',
|
||||
' ◆▦▦▦▦◆ ▥▥',
|
||||
' ◆▦▦◆ ▥▥',
|
||||
' ◆◆ ▥▥',
|
||||
'▥▥▥▥▥▥▥▥▥▥',
|
||||
'▥▥▥▥▥▥▥▥▥▥'
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('image without frame and with with some border left', async () => {
|
||||
const imgSrc = await Jimp.read(
|
||||
mkJGD(
|
||||
'323232323232',
|
||||
'232323232323',
|
||||
'32 ◆◆ 32',
|
||||
'23 ◆▦▦◆ 23',
|
||||
'32 ◆▦▦▦▦◆ 32',
|
||||
'23 ◆▦▦◆ 23',
|
||||
'32 ◆◆ 32',
|
||||
'232323232323',
|
||||
'323232323232'
|
||||
)
|
||||
);
|
||||
|
||||
imgSrc
|
||||
.autocrop({
|
||||
tolerance: 0.005,
|
||||
leaveBorder: 1
|
||||
})
|
||||
.getJGDSync()
|
||||
.should.be.sameJGD(
|
||||
mkJGD(
|
||||
'3232323232',
|
||||
'2 ◆◆ 3',
|
||||
'3 ◆▦▦◆ 2',
|
||||
'2 ◆▦▦▦▦◆ 3',
|
||||
'3 ◆▦▦◆ 2',
|
||||
'2 ◆◆ 3',
|
||||
'3232323232'
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('image with top and bottom frame and leaveBorder', async () => {
|
||||
const imgSrc = await Jimp.read(
|
||||
mkJGD(
|
||||
'▥▥▥▥▥▥▥▥',
|
||||
'▥▥▥▥▥▥▥▥',
|
||||
'▥▥▥▥▥▥▥▥',
|
||||
' ◆◆ ',
|
||||
' ◆▦▦◆ ',
|
||||
' ◆▦▦▦▦◆ ',
|
||||
' ◆▦▦◆ ',
|
||||
' ◆◆ ',
|
||||
'▥▥▥▥▥▥▥▥',
|
||||
'▥▥▥▥▥▥▥▥',
|
||||
'▥▥▥▥▥▥▥▥'
|
||||
)
|
||||
);
|
||||
imgSrc
|
||||
.autocrop({ cropSymmetric: true, cropOnlyFrames: false, leaveBorder: 2 })
|
||||
.getJGDSync()
|
||||
.should.be.sameJGD(
|
||||
mkJGD(
|
||||
'▥▥▥▥▥▥▥▥',
|
||||
'▥▥▥▥▥▥▥▥',
|
||||
' ◆◆ ',
|
||||
' ◆▦▦◆ ',
|
||||
' ◆▦▦▦▦◆ ',
|
||||
' ◆▦▦◆ ',
|
||||
' ◆◆ ',
|
||||
'▥▥▥▥▥▥▥▥',
|
||||
'▥▥▥▥▥▥▥▥'
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user