chore: add jimp dependency, icon padding script, and update configuration
This commit is contained in:
+97
@@ -0,0 +1,97 @@
|
||||
# v0.22.1 (Mon Feb 06 2023)
|
||||
|
||||
#### 🏠 Internal
|
||||
|
||||
- rename master to main [#1169](https://github.com/jimp-dev/jimp/pull/1169) ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
---
|
||||
|
||||
# v0.22.0 (Mon Feb 06 2023)
|
||||
|
||||
#### 🏠 Internal
|
||||
|
||||
- switch from should to expect [#1163](https://github.com/jimp-dev/jimp/pull/1163) ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
- Change test matching strategy to include all test files [#1161](https://github.com/jimp-dev/jimp/pull/1161) ([@danielholmes](https://github.com/danielholmes))
|
||||
|
||||
#### Authors: 2
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
- Daniel Holmes ([@danielholmes](https://github.com/danielholmes))
|
||||
|
||||
---
|
||||
|
||||
# v0.21.0 (Sun Feb 05 2023)
|
||||
|
||||
### Release Notes
|
||||
|
||||
#### Babel Refactor ([#1149](https://github.com/jimp-dev/jimp/pull/1149))
|
||||
|
||||
Marking this as a "breaking release" because it might change what deps need to be installed.
|
||||
|
||||
All modules should be exported as valid cjs and esm
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
#### 💥 Breaking Change
|
||||
|
||||
- Babel Refactor [#1149](https://github.com/jimp-dev/jimp/pull/1149) ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
---
|
||||
|
||||
# v0.16.3 (Sat Feb 04 2023)
|
||||
|
||||
#### ⚠️ Pushed to `main`
|
||||
|
||||
- upgrade prettier ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
---
|
||||
|
||||
# v0.11.0 (Fri May 15 2020)
|
||||
|
||||
#### 🚀 Enhancement
|
||||
|
||||
- Removed Core-JS as a dependency. [#882](https://github.com/oliver-moran/jimp/pull/882) ([@EricRabil](https://github.com/EricRabil))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Eric Rabil ([@EricRabil](https://github.com/EricRabil))
|
||||
|
||||
---
|
||||
|
||||
# v0.9.7 (Fri Mar 27 2020)
|
||||
|
||||
#### 🐛 Bug Fix
|
||||
|
||||
- Relax version range of plugin-threshold peerDependencies [#859](https://github.com/oliver-moran/jimp/pull/859) ([@pasieronen](https://github.com/pasieronen))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Pasi Eronen ([@pasieronen](https://github.com/pasieronen))
|
||||
|
||||
---
|
||||
|
||||
# v0.9.3 (Tue Nov 26 2019)
|
||||
|
||||
#### 🐛 Bug Fix
|
||||
|
||||
- `@jimp/cli`, `@jimp/core`, `@jimp/custom`, `jimp`, `@jimp/plugin-blit`, `@jimp/plugin-blur`, `@jimp/plugin-circle`, `@jimp/plugin-color`, `@jimp/plugin-contain`, `@jimp/plugin-cover`, `@jimp/plugin-crop`, `@jimp/plugin-displace`, `@jimp/plugin-dither`, `@jimp/plugin-fisheye`, `@jimp/plugin-flip`, `@jimp/plugin-gaussian`, `@jimp/plugin-invert`, `@jimp/plugin-mask`, `@jimp/plugin-normalize`, `@jimp/plugin-print`, `@jimp/plugin-resize`, `@jimp/plugin-rotate`, `@jimp/plugin-scale`, `@jimp/plugin-shadow`, `@jimp/plugin-threshold`, `@jimp/plugins`, `@jimp/test-utils`, `@jimp/bmp`, `@jimp/gif`, `@jimp/jpeg`, `@jimp/png`, `@jimp/tiff`, `@jimp/types`, `@jimp/utils`
|
||||
- Fix regeneratorRuntime errors [#815](https://github.com/oliver-moran/jimp/pull/815) ([@crutchcorn](https://github.com/crutchcorn) [@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
#### Authors: 2
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
- Corbin Crutchley ([@crutchcorn](https://github.com/crutchcorn))
|
||||
+21
@@ -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.
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<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-threshold</h1>
|
||||
<p>Lightens an image.</p>
|
||||
</div>
|
||||
|
||||
This is useful as a simplified method for processing scanned drawings, signatures, etc
|
||||
|
||||
## Usage
|
||||
|
||||
- @param {number} options object
|
||||
- max: A number auto limited between 0 - 255
|
||||
- replace: (optional) A number auto limited between 0 - 255 (default 255)
|
||||
- autoGreyscale: (optional) A boolean whether to apply greyscale beforehand (default true)
|
||||
- @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.threshold({ max: 150 });
|
||||
// or
|
||||
image.threshold({ max: 200, replace: 200, autoGreyscale: false });
|
||||
}
|
||||
|
||||
main();
|
||||
```
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
module.exports = (api) => {
|
||||
api.cache(true);
|
||||
|
||||
return {
|
||||
presets: [
|
||||
[
|
||||
"@babel/env",
|
||||
{
|
||||
useBuiltIns: "usage",
|
||||
},
|
||||
],
|
||||
],
|
||||
|
||||
plugins: [
|
||||
"@babel/proposal-class-properties",
|
||||
"@babel/syntax-object-rest-spread",
|
||||
process.env.BABEL_ENV !== "module" && "add-module-exports",
|
||||
[
|
||||
"transform-inline-environment-variables",
|
||||
{ include: ["BABEL_ENV", "ENV"] },
|
||||
],
|
||||
].filter(Boolean),
|
||||
|
||||
env: {
|
||||
test: {
|
||||
plugins: ["istanbul"],
|
||||
},
|
||||
development: {
|
||||
plugins: [process.env.ENV !== "browser" && "source-map-support"].filter(
|
||||
Boolean
|
||||
),
|
||||
},
|
||||
module: {
|
||||
presets: [["@babel/env", { modules: false }]],
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import { isNodePattern, throwError } from "@jimp/utils";
|
||||
|
||||
/**
|
||||
* Applies a minimum color threshold to a greyscale image. Converts image to greyscale by default
|
||||
* @param {number} options object
|
||||
* max: A number auto limited between 0 - 255
|
||||
* replace: (optional) A number auto limited between 0 - 255 (default 255)
|
||||
* autoGreyscale: (optional) A boolean whether to apply greyscale beforehand (default true)
|
||||
* @param {number} cb (optional) a callback for when complete
|
||||
* @return {this} this for chaining of methods
|
||||
*/
|
||||
export default (() => ({
|
||||
threshold(_ref, cb) {
|
||||
let {
|
||||
max,
|
||||
replace = 255,
|
||||
autoGreyscale = true
|
||||
} = _ref;
|
||||
if (typeof max !== "number") {
|
||||
return throwError.call(this, "max must be a number", cb);
|
||||
}
|
||||
if (typeof replace !== "number") {
|
||||
return throwError.call(this, "replace must be a number", cb);
|
||||
}
|
||||
if (typeof autoGreyscale !== "boolean") {
|
||||
return throwError.call(this, "autoGreyscale must be a boolean", cb);
|
||||
}
|
||||
max = this.constructor.limit255(max);
|
||||
replace = this.constructor.limit255(replace);
|
||||
if (autoGreyscale) {
|
||||
this.greyscale();
|
||||
}
|
||||
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, (x, y, idx) => {
|
||||
const grey = this.bitmap.data[idx] < max ? this.bitmap.data[idx] : replace;
|
||||
this.bitmap.data[idx] = grey;
|
||||
this.bitmap.data[idx + 1] = grey;
|
||||
this.bitmap.data[idx + 2] = grey;
|
||||
});
|
||||
if (isNodePattern(cb)) {
|
||||
cb.call(this, null, this);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}));
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","names":["isNodePattern","throwError","threshold","cb","max","replace","autoGreyscale","call","constructor","limit255","greyscale","scanQuiet","bitmap","width","height","x","y","idx","grey","data"],"sources":["../src/index.js"],"sourcesContent":["import { isNodePattern, throwError } from \"@jimp/utils\";\n\n/**\n * Applies a minimum color threshold to a greyscale image. Converts image to greyscale by default\n * @param {number} options object\n * max: A number auto limited between 0 - 255\n * replace: (optional) A number auto limited between 0 - 255 (default 255)\n * autoGreyscale: (optional) A boolean whether to apply greyscale beforehand (default true)\n * @param {number} cb (optional) a callback for when complete\n * @return {this} this for chaining of methods\n */\nexport default () => ({\n threshold({ max, replace = 255, autoGreyscale = true }, cb) {\n if (typeof max !== \"number\") {\n return throwError.call(this, \"max must be a number\", cb);\n }\n\n if (typeof replace !== \"number\") {\n return throwError.call(this, \"replace must be a number\", cb);\n }\n\n if (typeof autoGreyscale !== \"boolean\") {\n return throwError.call(this, \"autoGreyscale must be a boolean\", cb);\n }\n\n max = this.constructor.limit255(max);\n replace = this.constructor.limit255(replace);\n\n if (autoGreyscale) {\n this.greyscale();\n }\n\n this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, (x, y, idx) => {\n const grey =\n this.bitmap.data[idx] < max ? this.bitmap.data[idx] : replace;\n\n this.bitmap.data[idx] = grey;\n this.bitmap.data[idx + 1] = grey;\n this.bitmap.data[idx + 2] = grey;\n });\n\n if (isNodePattern(cb)) {\n cb.call(this, null, this);\n }\n\n return this;\n },\n});\n"],"mappings":"AAAA,SAASA,aAAa,EAAEC,UAAU,QAAQ,aAAa;;AAEvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAe,OAAO;EACpBC,SAAS,OAA+CC,EAAE,EAAE;IAAA,IAAlD;MAAEC,GAAG;MAAEC,OAAO,GAAG,GAAG;MAAEC,aAAa,GAAG;IAAK,CAAC;IACpD,IAAI,OAAOF,GAAG,KAAK,QAAQ,EAAE;MAC3B,OAAOH,UAAU,CAACM,IAAI,CAAC,IAAI,EAAE,sBAAsB,EAAEJ,EAAE,CAAC;IAC1D;IAEA,IAAI,OAAOE,OAAO,KAAK,QAAQ,EAAE;MAC/B,OAAOJ,UAAU,CAACM,IAAI,CAAC,IAAI,EAAE,0BAA0B,EAAEJ,EAAE,CAAC;IAC9D;IAEA,IAAI,OAAOG,aAAa,KAAK,SAAS,EAAE;MACtC,OAAOL,UAAU,CAACM,IAAI,CAAC,IAAI,EAAE,iCAAiC,EAAEJ,EAAE,CAAC;IACrE;IAEAC,GAAG,GAAG,IAAI,CAACI,WAAW,CAACC,QAAQ,CAACL,GAAG,CAAC;IACpCC,OAAO,GAAG,IAAI,CAACG,WAAW,CAACC,QAAQ,CAACJ,OAAO,CAAC;IAE5C,IAAIC,aAAa,EAAE;MACjB,IAAI,CAACI,SAAS,EAAE;IAClB;IAEA,IAAI,CAACC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAACC,MAAM,CAACC,KAAK,EAAE,IAAI,CAACD,MAAM,CAACE,MAAM,EAAE,CAACC,CAAC,EAAEC,CAAC,EAAEC,GAAG,KAAK;MACzE,MAAMC,IAAI,GACR,IAAI,CAACN,MAAM,CAACO,IAAI,CAACF,GAAG,CAAC,GAAGb,GAAG,GAAG,IAAI,CAACQ,MAAM,CAACO,IAAI,CAACF,GAAG,CAAC,GAAGZ,OAAO;MAE/D,IAAI,CAACO,MAAM,CAACO,IAAI,CAACF,GAAG,CAAC,GAAGC,IAAI;MAC5B,IAAI,CAACN,MAAM,CAACO,IAAI,CAACF,GAAG,GAAG,CAAC,CAAC,GAAGC,IAAI;MAChC,IAAI,CAACN,MAAM,CAACO,IAAI,CAACF,GAAG,GAAG,CAAC,CAAC,GAAGC,IAAI;IAClC,CAAC,CAAC;IAEF,IAAIlB,aAAa,CAACG,EAAE,CAAC,EAAE;MACrBA,EAAE,CAACI,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;IAC3B;IAEA,OAAO,IAAI;EACb;AACF,CAAC,CAAC"}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { ImageCallback } from "@jimp/core";
|
||||
|
||||
interface Threshold {
|
||||
threshold(
|
||||
opts: {
|
||||
max: number;
|
||||
replace?: number;
|
||||
autoGreyscale?: boolean;
|
||||
},
|
||||
cb?: ImageCallback<this>
|
||||
): this;
|
||||
}
|
||||
|
||||
export default function (): Threshold;
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "@jimp/plugin-threshold",
|
||||
"version": "0.22.12",
|
||||
"description": "Lightens an image.",
|
||||
"main": "dist/index.js",
|
||||
"module": "es/index.js",
|
||||
"repository": "jimp-dev/jimp",
|
||||
"types": "index.d.ts",
|
||||
"scripts": {
|
||||
"test": "cross-env BABEL_ENV=test mocha --require @babel/register --recursive test --extension js",
|
||||
"test:watch": "npm run test -- --reporter min --watch",
|
||||
"test:coverage": "nyc npm run test",
|
||||
"build": "npm run build:node:production && npm run build:module",
|
||||
"build:watch": "npm run build:node:debug -- -- --watch --verbose",
|
||||
"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"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jimp/utils": "^0.22.12"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@jimp/custom": ">=0.3.5",
|
||||
"@jimp/plugin-color": ">=0.8.0",
|
||||
"@jimp/plugin-resize": ">=0.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@jimp/custom": "^0.22.12",
|
||||
"@jimp/jpeg": "^0.22.12",
|
||||
"@jimp/plugin-color": "^0.22.12",
|
||||
"@jimp/plugin-resize": "^0.22.12",
|
||||
"@jimp/test-utils": "^0.22.12"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"gitHead": "a4a8d6364bbf97629749e196f3b0a4c94c9a7abc"
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
import { isNodePattern, throwError } from "@jimp/utils";
|
||||
|
||||
/**
|
||||
* Applies a minimum color threshold to a greyscale image. Converts image to greyscale by default
|
||||
* @param {number} options object
|
||||
* max: A number auto limited between 0 - 255
|
||||
* replace: (optional) A number auto limited between 0 - 255 (default 255)
|
||||
* autoGreyscale: (optional) A boolean whether to apply greyscale beforehand (default true)
|
||||
* @param {number} cb (optional) a callback for when complete
|
||||
* @return {this} this for chaining of methods
|
||||
*/
|
||||
export default () => ({
|
||||
threshold({ max, replace = 255, autoGreyscale = true }, cb) {
|
||||
if (typeof max !== "number") {
|
||||
return throwError.call(this, "max must be a number", cb);
|
||||
}
|
||||
|
||||
if (typeof replace !== "number") {
|
||||
return throwError.call(this, "replace must be a number", cb);
|
||||
}
|
||||
|
||||
if (typeof autoGreyscale !== "boolean") {
|
||||
return throwError.call(this, "autoGreyscale must be a boolean", cb);
|
||||
}
|
||||
|
||||
max = this.constructor.limit255(max);
|
||||
replace = this.constructor.limit255(replace);
|
||||
|
||||
if (autoGreyscale) {
|
||||
this.greyscale();
|
||||
}
|
||||
|
||||
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, (x, y, idx) => {
|
||||
const grey =
|
||||
this.bitmap.data[idx] < max ? this.bitmap.data[idx] : replace;
|
||||
|
||||
this.bitmap.data[idx] = grey;
|
||||
this.bitmap.data[idx + 1] = grey;
|
||||
this.bitmap.data[idx + 2] = grey;
|
||||
});
|
||||
|
||||
if (isNodePattern(cb)) {
|
||||
cb.call(this, null, this);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
});
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 207 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 431 KiB |
+30
@@ -0,0 +1,30 @@
|
||||
import { Jimp, getTestDir } from "@jimp/test-utils";
|
||||
import configure from "@jimp/custom";
|
||||
import jpeg from "@jimp/jpeg";
|
||||
import color from "@jimp/plugin-color";
|
||||
import resize from "@jimp/plugin-resize";
|
||||
import expect from "@storybook/expect";
|
||||
|
||||
import threshold from "../src";
|
||||
|
||||
const jimp = configure(
|
||||
{ types: [jpeg], plugins: [threshold, color, resize] },
|
||||
Jimp
|
||||
);
|
||||
|
||||
describe("Threshold", function () {
|
||||
this.timeout(15000);
|
||||
|
||||
it("defines default threshold for lighter backgrounds", async () => {
|
||||
const expectedImage = await jimp.read(
|
||||
getTestDir(__dirname) + "/images/hands_mx200_rp255.jpg"
|
||||
);
|
||||
const testImage = await jimp.read(
|
||||
getTestDir(__dirname) + "/images/hands.jpg"
|
||||
);
|
||||
|
||||
expect(testImage.threshold({ max: 200, replace: 255 }).hash()).toBe(
|
||||
expectedImage.hash()
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user