chore: add jimp dependency, icon padding script, and update configuration
This commit is contained in:
+131
@@ -0,0 +1,131 @@
|
||||
# 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))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
---
|
||||
|
||||
# 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.18.0 (Sun Feb 05 2023)
|
||||
|
||||
### Release Notes
|
||||
|
||||
#### switch from browserify to webpack ([#1140](https://github.com/jimp-dev/jimp/pull/1140))
|
||||
|
||||
This PR can be considered a breaking change as it remove the `jimp.min.js` file.
|
||||
|
||||
Instead there is now only the `jimp.js` file and we ship source maps for it.
|
||||
|
||||
We also configured the `browser` field so jimp will be automatically bundled better
|
||||
|
||||
---
|
||||
|
||||
#### 💥 Breaking Change
|
||||
|
||||
- switch from browserify to webpack [#1140](https://github.com/jimp-dev/jimp/pull/1140) ([@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.10.0 (Mon Mar 30 2020)
|
||||
|
||||
#### 🚀 Enhancement
|
||||
|
||||
- Properly split constructor and instance types [#867](https://github.com/oliver-moran/jimp/pull/867) ([@forivall](https://github.com/forivall))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Emily Marigold Klassen ([@forivall](https://github.com/forivall))
|
||||
|
||||
---
|
||||
|
||||
# v0.9.6 (Wed Mar 18 2020)
|
||||
|
||||
#### 🏠 Internal
|
||||
|
||||
- Fix TypeScript error on 'next' [#858](https://github.com/oliver-moran/jimp/pull/858) ([@crutchcorn](https://github.com/crutchcorn))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Corbin Crutchley ([@crutchcorn](https://github.com/crutchcorn))
|
||||
|
||||
---
|
||||
|
||||
# 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.
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
<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/custom</h1>
|
||||
<p>Configure jimp with types and plugins.</p>
|
||||
</div>
|
||||
|
||||
## Useful Defaults
|
||||
|
||||
The following wil configure a `jimp` instance with the same functionality as the main `jimp` package.
|
||||
|
||||
```js
|
||||
import configure from "@jimp/custom";
|
||||
// all of jimp's default types
|
||||
import types from "@jimp/types";
|
||||
// all of jimp's default types
|
||||
import plugins from "@jimp/plugins";
|
||||
|
||||
configure({
|
||||
types: [types],
|
||||
plugins: [plugins],
|
||||
});
|
||||
```
|
||||
|
||||
## Available Methods
|
||||
|
||||
### configure
|
||||
|
||||
Takes a Jimp configuration and applies it to `@jimp/core`.
|
||||
|
||||
Sample Jimp configuration:
|
||||
|
||||
```js
|
||||
import types from '@jimp/types';
|
||||
|
||||
import bmp from '@jimp/bmp';
|
||||
import jpeg from '@jimp/types';
|
||||
...
|
||||
|
||||
configure({
|
||||
types: [types]
|
||||
})
|
||||
|
||||
// or
|
||||
|
||||
configure({
|
||||
types: [bmp, jpeg, ...]
|
||||
})
|
||||
```
|
||||
|
||||
#### Extending Jimp Further
|
||||
|
||||
You can use configure to add more types and plugins to a jimp multiple times.
|
||||
|
||||
```js
|
||||
let jimp = configure({
|
||||
types: [bmp],
|
||||
});
|
||||
|
||||
jimp = configure(
|
||||
{
|
||||
types: [jpeg],
|
||||
},
|
||||
jimp
|
||||
);
|
||||
```
|
||||
|
||||
## Type Definition
|
||||
|
||||
To define a new Jimp image type write a function the takes the current Jimp configuration. In this function you can extend Jimp's internal data structures.
|
||||
|
||||
This function must return an object whose key is the mime type and value is an array of valid file extensions.
|
||||
|
||||
```js
|
||||
const special = require('special-js');
|
||||
|
||||
const MIME_TYPE = 'image/special';
|
||||
|
||||
export default () => ({
|
||||
mime: {[MIME_TYPE], ['spec', 'special']},
|
||||
|
||||
constants: {
|
||||
MIME_SPECIAL: MIME_TYPE
|
||||
},
|
||||
|
||||
decoders: {
|
||||
[MIME_TYPE]: data => special.decode(data)
|
||||
},
|
||||
|
||||
encoders: {
|
||||
[MIME_TYPE]: image => special.encode(image.bitmap)
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Constants
|
||||
|
||||
A jimp image type can expose as many constants as it wants. Each jimp type is required to expose a mime type.
|
||||
|
||||
```js
|
||||
constants: {
|
||||
MIME_SPECIAL: MIME_TYPE
|
||||
},
|
||||
```
|
||||
|
||||
### hasAlpha
|
||||
|
||||
A image type can define whether it supports an alpha channel.
|
||||
|
||||
```js
|
||||
hasAlpha: {
|
||||
MIME_SPECIAL: true
|
||||
},
|
||||
```
|
||||
|
||||
### Decoder
|
||||
|
||||
A function that when supplied with a buffer should return a bitmap with height and width.
|
||||
|
||||
```js
|
||||
decoders: {
|
||||
[MIME_TYPE]: data => special.decode(data)
|
||||
},
|
||||
```
|
||||
|
||||
### Encoder
|
||||
|
||||
A function that when supplied with a Jimp image should return an encoded buffer.
|
||||
|
||||
```js
|
||||
encoders: {
|
||||
[MIME_TYPE]: image => special.encode(image.bitmap)
|
||||
}
|
||||
```
|
||||
|
||||
### Class
|
||||
|
||||
Add class properties and function to the Jimp constructor.
|
||||
|
||||
```js
|
||||
class: {
|
||||
_quality: 100,
|
||||
quality: function(n, cb) {
|
||||
if (typeof n !== 'number') {
|
||||
return throwError.call(this, 'n must be a number', cb);
|
||||
}
|
||||
|
||||
if (n < 0 || n > 100) {
|
||||
return throwError.call(this, 'n must be a number 0 - 100', cb);
|
||||
}
|
||||
|
||||
this._quality = Math.round(n);
|
||||
|
||||
if (isNodePattern(cb)) {
|
||||
cb.call(this, null, this);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
## Plugin Definition
|
||||
|
||||
Defining a plugin has access to all the same things in the type definition. Mainly plugins use just the `constants` and `class` config options.
|
||||
|
||||
Below is the `invert` plugin. If a plugin doesn return an object with `constants` and `class`, all keys are treated as class functions.
|
||||
|
||||
```js
|
||||
import { isNodePattern } from "@jimp/utils";
|
||||
|
||||
/**
|
||||
* Inverts the image
|
||||
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
|
||||
* @returns {Jimp} this for chaining of methods
|
||||
*/
|
||||
export default () => ({
|
||||
invert(cb) {
|
||||
this.scanQuiet(
|
||||
0,
|
||||
0,
|
||||
this.bitmap.width,
|
||||
this.bitmap.height,
|
||||
function (x, y, idx) {
|
||||
this.bitmap.data[idx] = 255 - this.bitmap.data[idx];
|
||||
this.bitmap.data[idx + 1] = 255 - this.bitmap.data[idx + 1];
|
||||
this.bitmap.data[idx + 2] = 255 - this.bitmap.data[idx + 2];
|
||||
}
|
||||
);
|
||||
|
||||
if (isNodePattern(cb)) {
|
||||
cb.call(this, null, this);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
});
|
||||
```
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
import Jimp, { addType, addJimpMethods, addConstants, jimpEvChange } from "@jimp/core";
|
||||
export default function configure(configuration) {
|
||||
let jimpInstance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Jimp;
|
||||
const jimpConfig = {
|
||||
hasAlpha: {},
|
||||
encoders: {},
|
||||
decoders: {},
|
||||
class: {},
|
||||
constants: {}
|
||||
};
|
||||
function addToConfig(newConfig) {
|
||||
Object.entries(newConfig).forEach(_ref => {
|
||||
let [key, value] = _ref;
|
||||
jimpConfig[key] = {
|
||||
...jimpConfig[key],
|
||||
...value
|
||||
};
|
||||
});
|
||||
}
|
||||
function addImageType(typeModule) {
|
||||
const type = typeModule();
|
||||
if (Array.isArray(type.mime)) {
|
||||
addType(...type.mime);
|
||||
} else {
|
||||
Object.entries(type.mime).forEach(mimeType => addType(...mimeType));
|
||||
}
|
||||
delete type.mime;
|
||||
addToConfig(type);
|
||||
}
|
||||
function addPlugin(pluginModule) {
|
||||
const plugin = pluginModule(jimpEvChange) || {};
|
||||
if (!plugin.class && !plugin.constants) {
|
||||
// Default to class function
|
||||
addToConfig({
|
||||
class: plugin
|
||||
});
|
||||
} else {
|
||||
addToConfig(plugin);
|
||||
}
|
||||
}
|
||||
if (configuration.types) {
|
||||
configuration.types.forEach(addImageType);
|
||||
jimpInstance.decoders = {
|
||||
...jimpInstance.decoders,
|
||||
...jimpConfig.decoders
|
||||
};
|
||||
jimpInstance.encoders = {
|
||||
...jimpInstance.encoders,
|
||||
...jimpConfig.encoders
|
||||
};
|
||||
jimpInstance.hasAlpha = {
|
||||
...jimpInstance.hasAlpha,
|
||||
...jimpConfig.hasAlpha
|
||||
};
|
||||
}
|
||||
if (configuration.plugins) {
|
||||
configuration.plugins.forEach(addPlugin);
|
||||
}
|
||||
addJimpMethods(jimpConfig.class, jimpInstance);
|
||||
addConstants(jimpConfig.constants, jimpInstance);
|
||||
return Jimp;
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","names":["Jimp","addType","addJimpMethods","addConstants","jimpEvChange","configure","configuration","jimpInstance","jimpConfig","hasAlpha","encoders","decoders","class","constants","addToConfig","newConfig","Object","entries","forEach","key","value","addImageType","typeModule","type","Array","isArray","mime","mimeType","addPlugin","pluginModule","plugin","types","plugins"],"sources":["../src/index.js"],"sourcesContent":["import Jimp, {\n addType,\n addJimpMethods,\n addConstants,\n jimpEvChange,\n} from \"@jimp/core\";\n\nexport default function configure(configuration, jimpInstance = Jimp) {\n const jimpConfig = {\n hasAlpha: {},\n encoders: {},\n decoders: {},\n class: {},\n constants: {},\n };\n\n function addToConfig(newConfig) {\n Object.entries(newConfig).forEach(([key, value]) => {\n jimpConfig[key] = {\n ...jimpConfig[key],\n ...value,\n };\n });\n }\n\n function addImageType(typeModule) {\n const type = typeModule();\n\n if (Array.isArray(type.mime)) {\n addType(...type.mime);\n } else {\n Object.entries(type.mime).forEach((mimeType) => addType(...mimeType));\n }\n\n delete type.mime;\n addToConfig(type);\n }\n\n function addPlugin(pluginModule) {\n const plugin = pluginModule(jimpEvChange) || {};\n if (!plugin.class && !plugin.constants) {\n // Default to class function\n addToConfig({ class: plugin });\n } else {\n addToConfig(plugin);\n }\n }\n\n if (configuration.types) {\n configuration.types.forEach(addImageType);\n\n jimpInstance.decoders = {\n ...jimpInstance.decoders,\n ...jimpConfig.decoders,\n };\n jimpInstance.encoders = {\n ...jimpInstance.encoders,\n ...jimpConfig.encoders,\n };\n jimpInstance.hasAlpha = {\n ...jimpInstance.hasAlpha,\n ...jimpConfig.hasAlpha,\n };\n }\n\n if (configuration.plugins) {\n configuration.plugins.forEach(addPlugin);\n }\n\n addJimpMethods(jimpConfig.class, jimpInstance);\n addConstants(jimpConfig.constants, jimpInstance);\n\n return Jimp;\n}\n"],"mappings":"AAAA,OAAOA,IAAI,IACTC,OAAO,EACPC,cAAc,EACdC,YAAY,EACZC,YAAY,QACP,YAAY;AAEnB,eAAe,SAASC,SAAS,CAACC,aAAa,EAAuB;EAAA,IAArBC,YAAY,uEAAGP,IAAI;EAClE,MAAMQ,UAAU,GAAG;IACjBC,QAAQ,EAAE,CAAC,CAAC;IACZC,QAAQ,EAAE,CAAC,CAAC;IACZC,QAAQ,EAAE,CAAC,CAAC;IACZC,KAAK,EAAE,CAAC,CAAC;IACTC,SAAS,EAAE,CAAC;EACd,CAAC;EAED,SAASC,WAAW,CAACC,SAAS,EAAE;IAC9BC,MAAM,CAACC,OAAO,CAACF,SAAS,CAAC,CAACG,OAAO,CAAC,QAAkB;MAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC;MAC7CZ,UAAU,CAACW,GAAG,CAAC,GAAG;QAChB,GAAGX,UAAU,CAACW,GAAG,CAAC;QAClB,GAAGC;MACL,CAAC;IACH,CAAC,CAAC;EACJ;EAEA,SAASC,YAAY,CAACC,UAAU,EAAE;IAChC,MAAMC,IAAI,GAAGD,UAAU,EAAE;IAEzB,IAAIE,KAAK,CAACC,OAAO,CAACF,IAAI,CAACG,IAAI,CAAC,EAAE;MAC5BzB,OAAO,CAAC,GAAGsB,IAAI,CAACG,IAAI,CAAC;IACvB,CAAC,MAAM;MACLV,MAAM,CAACC,OAAO,CAACM,IAAI,CAACG,IAAI,CAAC,CAACR,OAAO,CAAES,QAAQ,IAAK1B,OAAO,CAAC,GAAG0B,QAAQ,CAAC,CAAC;IACvE;IAEA,OAAOJ,IAAI,CAACG,IAAI;IAChBZ,WAAW,CAACS,IAAI,CAAC;EACnB;EAEA,SAASK,SAAS,CAACC,YAAY,EAAE;IAC/B,MAAMC,MAAM,GAAGD,YAAY,CAACzB,YAAY,CAAC,IAAI,CAAC,CAAC;IAC/C,IAAI,CAAC0B,MAAM,CAAClB,KAAK,IAAI,CAACkB,MAAM,CAACjB,SAAS,EAAE;MACtC;MACAC,WAAW,CAAC;QAAEF,KAAK,EAAEkB;MAAO,CAAC,CAAC;IAChC,CAAC,MAAM;MACLhB,WAAW,CAACgB,MAAM,CAAC;IACrB;EACF;EAEA,IAAIxB,aAAa,CAACyB,KAAK,EAAE;IACvBzB,aAAa,CAACyB,KAAK,CAACb,OAAO,CAACG,YAAY,CAAC;IAEzCd,YAAY,CAACI,QAAQ,GAAG;MACtB,GAAGJ,YAAY,CAACI,QAAQ;MACxB,GAAGH,UAAU,CAACG;IAChB,CAAC;IACDJ,YAAY,CAACG,QAAQ,GAAG;MACtB,GAAGH,YAAY,CAACG,QAAQ;MACxB,GAAGF,UAAU,CAACE;IAChB,CAAC;IACDH,YAAY,CAACE,QAAQ,GAAG;MACtB,GAAGF,YAAY,CAACE,QAAQ;MACxB,GAAGD,UAAU,CAACC;IAChB,CAAC;EACH;EAEA,IAAIH,aAAa,CAAC0B,OAAO,EAAE;IACzB1B,aAAa,CAAC0B,OAAO,CAACd,OAAO,CAACU,SAAS,CAAC;EAC1C;EAEA1B,cAAc,CAACM,UAAU,CAACI,KAAK,EAAEL,YAAY,CAAC;EAC9CJ,YAAY,CAACK,UAAU,CAACK,SAAS,EAAEN,YAAY,CAAC;EAEhD,OAAOP,IAAI;AACb"}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "@jimp/custom",
|
||||
"version": "0.22.12",
|
||||
"description": "Interface to customize jimp configuration",
|
||||
"main": "dist/index.js",
|
||||
"module": "es/index.js",
|
||||
"repository": "jimp-dev/jimp",
|
||||
"types": "types/index.d.ts",
|
||||
"scripts": {
|
||||
"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/core": "^0.22.12"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"gitHead": "a4a8d6364bbf97629749e196f3b0a4c94c9a7abc"
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
import Jimp, {
|
||||
addType,
|
||||
addJimpMethods,
|
||||
addConstants,
|
||||
jimpEvChange,
|
||||
} from "@jimp/core";
|
||||
|
||||
export default function configure(configuration, jimpInstance = Jimp) {
|
||||
const jimpConfig = {
|
||||
hasAlpha: {},
|
||||
encoders: {},
|
||||
decoders: {},
|
||||
class: {},
|
||||
constants: {},
|
||||
};
|
||||
|
||||
function addToConfig(newConfig) {
|
||||
Object.entries(newConfig).forEach(([key, value]) => {
|
||||
jimpConfig[key] = {
|
||||
...jimpConfig[key],
|
||||
...value,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function addImageType(typeModule) {
|
||||
const type = typeModule();
|
||||
|
||||
if (Array.isArray(type.mime)) {
|
||||
addType(...type.mime);
|
||||
} else {
|
||||
Object.entries(type.mime).forEach((mimeType) => addType(...mimeType));
|
||||
}
|
||||
|
||||
delete type.mime;
|
||||
addToConfig(type);
|
||||
}
|
||||
|
||||
function addPlugin(pluginModule) {
|
||||
const plugin = pluginModule(jimpEvChange) || {};
|
||||
if (!plugin.class && !plugin.constants) {
|
||||
// Default to class function
|
||||
addToConfig({ class: plugin });
|
||||
} else {
|
||||
addToConfig(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
if (configuration.types) {
|
||||
configuration.types.forEach(addImageType);
|
||||
|
||||
jimpInstance.decoders = {
|
||||
...jimpInstance.decoders,
|
||||
...jimpConfig.decoders,
|
||||
};
|
||||
jimpInstance.encoders = {
|
||||
...jimpInstance.encoders,
|
||||
...jimpConfig.encoders,
|
||||
};
|
||||
jimpInstance.hasAlpha = {
|
||||
...jimpInstance.hasAlpha,
|
||||
...jimpConfig.hasAlpha,
|
||||
};
|
||||
}
|
||||
|
||||
if (configuration.plugins) {
|
||||
configuration.plugins.forEach(addPlugin);
|
||||
}
|
||||
|
||||
addJimpMethods(jimpConfig.class, jimpInstance);
|
||||
addConstants(jimpConfig.constants, jimpInstance);
|
||||
|
||||
return Jimp;
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// Minimum TypeScript Version: 3.2
|
||||
// See the `jimp` package index.d.ts for why the version is not 2.8
|
||||
import {
|
||||
FunctionRet,
|
||||
Jimp,
|
||||
JimpPlugin,
|
||||
JimpType,
|
||||
GetIntersectionFromPlugins,
|
||||
GetIntersectionFromPluginsStatics,
|
||||
JimpConstructors,
|
||||
} from "@jimp/core";
|
||||
|
||||
type JimpInstance<
|
||||
TypesFuncArr extends FunctionRet<JimpType> | undefined,
|
||||
PluginFuncArr extends FunctionRet<JimpPlugin> | undefined,
|
||||
J extends JimpConstructors
|
||||
> = J &
|
||||
GetIntersectionFromPluginsStatics<
|
||||
Exclude<TypesFuncArr | PluginFuncArr, undefined>
|
||||
> & {
|
||||
prototype: JimpType &
|
||||
GetIntersectionFromPlugins<
|
||||
Exclude<TypesFuncArr | PluginFuncArr, undefined>
|
||||
>;
|
||||
};
|
||||
|
||||
declare function configure<
|
||||
TypesFuncArr extends FunctionRet<JimpType> | undefined = undefined,
|
||||
PluginFuncArr extends FunctionRet<JimpPlugin> | undefined = undefined,
|
||||
J extends JimpConstructors = JimpConstructors
|
||||
>(
|
||||
configuration: {
|
||||
types?: TypesFuncArr;
|
||||
plugins?: PluginFuncArr;
|
||||
},
|
||||
jimpInstance?: J
|
||||
// Since JimpInstance is required, we want to use the default `Jimp` type
|
||||
): JimpInstance<TypesFuncArr, PluginFuncArr, J>;
|
||||
|
||||
export default configure;
|
||||
+401
@@ -0,0 +1,401 @@
|
||||
import configure from "@jimp/custom";
|
||||
import gif from "@jimp/gif";
|
||||
import png from "@jimp/png";
|
||||
import displace from "@jimp/plugin-displace";
|
||||
import resize from "@jimp/plugin-resize";
|
||||
import scale from "@jimp/plugin-scale";
|
||||
import types from "@jimp/types";
|
||||
import plugins from "@jimp/plugins";
|
||||
import * as Jimp from "jimp";
|
||||
|
||||
// configure should return a valid Jimp type with addons
|
||||
const CustomJimp = configure({
|
||||
types: [gif, png],
|
||||
plugins: [displace, resize],
|
||||
});
|
||||
|
||||
test("should function the same as the `jimp` types", () => {
|
||||
const FullCustomJimp = configure({
|
||||
types: [types],
|
||||
plugins: [plugins],
|
||||
});
|
||||
|
||||
const jimpInst = new FullCustomJimp("test");
|
||||
|
||||
// Main Jimp export should already have all of these already applied
|
||||
// $ExpectError
|
||||
jimpInst.read("Test");
|
||||
jimpInst.displace(jimpInst, 2);
|
||||
jimpInst.resize(40, 40);
|
||||
jimpInst.displace(jimpInst, 2);
|
||||
jimpInst.shadow((err, val, coords) => {});
|
||||
jimpInst.fishEye({ r: 12 });
|
||||
jimpInst.circle({ radius: 12, x: 12, y: 12 });
|
||||
// $ExpectError
|
||||
jimpInst.PNG_FILTER_NONE;
|
||||
|
||||
// $ExpectError
|
||||
jimpInst.test;
|
||||
|
||||
// $ExpectError
|
||||
jimpInst.func();
|
||||
|
||||
// Main Jimp export should already have all of these already applied
|
||||
FullCustomJimp.read("Test");
|
||||
|
||||
// $ExpectType 0
|
||||
FullCustomJimp.PNG_FILTER_NONE;
|
||||
|
||||
// $ExpectError
|
||||
FullCustomJimp.test;
|
||||
|
||||
// $ExpectError
|
||||
FullCustomJimp.func();
|
||||
|
||||
test("can clone properly", async () => {
|
||||
const baseImage = await FullCustomJimp.read("filename");
|
||||
const cloneBaseImage = baseImage.clone();
|
||||
|
||||
// $ExpectType number
|
||||
cloneBaseImage._deflateLevel;
|
||||
|
||||
test("can handle `this` returns on the core type properly", () => {
|
||||
// $ExpectType number
|
||||
cloneBaseImage.posterize(3)._quality;
|
||||
});
|
||||
|
||||
test("can handle `this` returns properly", () => {
|
||||
cloneBaseImage
|
||||
.resize(1, 1)
|
||||
.crop(0, 0, 0, 0)
|
||||
.mask(cloneBaseImage, 2, 2)
|
||||
.print("a" as any, 2, 2, "a" as any)
|
||||
.resize(1, 1)
|
||||
.quality(1)
|
||||
.deflateLevel(2)._filterType;
|
||||
});
|
||||
|
||||
test("can handle imageCallbacks `this` properly", () => {
|
||||
cloneBaseImage.rgba(false, (_, jimpCBIn) => {
|
||||
// $ExpectError
|
||||
jimpCBIn.read("Test");
|
||||
jimpCBIn.displace(jimpInst, 2);
|
||||
jimpCBIn.resize(40, 40);
|
||||
// $ExpectType number
|
||||
jimpCBIn._filterType;
|
||||
|
||||
// $ExpectError
|
||||
jimpCBIn.test;
|
||||
|
||||
// $ExpectError
|
||||
jimpCBIn.func();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test("Can handle callback with constructor", () => {
|
||||
const myBmpBuffer: Buffer = {} as any;
|
||||
|
||||
Jimp.read(myBmpBuffer, (err, cbJimpInst) => {
|
||||
// $ExpectError
|
||||
cbJimpInst.read("Test");
|
||||
cbJimpInst.displace(jimpInst, 2);
|
||||
cbJimpInst.resize(40, 40);
|
||||
// $ExpectType number
|
||||
cbJimpInst._filterType;
|
||||
|
||||
// $ExpectError
|
||||
cbJimpInst.test;
|
||||
|
||||
// $ExpectError
|
||||
cbJimpInst.func();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test("can handle custom jimp", () => {
|
||||
// Constants from types should be applied
|
||||
// $ExpectType 0
|
||||
CustomJimp.PNG_FILTER_NONE;
|
||||
|
||||
// Core functions should still work from Jimp
|
||||
CustomJimp.read("Test");
|
||||
|
||||
// Constants should not(?) be applied from ill-formed plugins
|
||||
// $ExpectError
|
||||
CustomJimp.displace(CustomJimp, 2);
|
||||
|
||||
// Methods should be applied from well-formed plugins only to the instance
|
||||
// $ExpectError
|
||||
CustomJimp.resize(40, 40);
|
||||
|
||||
// Constants should be applied from well-formed plugins
|
||||
CustomJimp.RESIZE_NEAREST_NEIGHBOR;
|
||||
|
||||
// $ExpectError
|
||||
CustomJimp.test;
|
||||
|
||||
// $ExpectError
|
||||
CustomJimp.func();
|
||||
|
||||
const Jiimp = new CustomJimp("test");
|
||||
// Methods from types should be applied
|
||||
Jiimp.deflateLevel(4);
|
||||
// Constants from types should be applied to the static only
|
||||
// $ExpectError
|
||||
Jiimp.PNG_FILTER_NONE;
|
||||
|
||||
// Core functions should still work from Jimp
|
||||
Jiimp.getPixelColor(1, 1);
|
||||
|
||||
// Constants should be applied from ill-formed plugins
|
||||
Jiimp.displace(Jiimp, 2);
|
||||
|
||||
// Methods should be applied from well-formed plugins
|
||||
Jiimp.resize(40, 40);
|
||||
|
||||
// Constants should not be applied to the object
|
||||
// $ExpectError
|
||||
Jiimp.RESIZE_NEAREST_NEIGHBOR;
|
||||
|
||||
// $ExpectError
|
||||
Jiimp.test;
|
||||
|
||||
// $ExpectError
|
||||
Jiimp.func();
|
||||
});
|
||||
|
||||
test("can compose", () => {
|
||||
const OtherCustomJimp = configure(
|
||||
{
|
||||
plugins: [scale],
|
||||
},
|
||||
CustomJimp
|
||||
);
|
||||
// Constants from types should be applied
|
||||
// $ExpectType 0
|
||||
OtherCustomJimp.PNG_FILTER_NONE;
|
||||
|
||||
// Core functions should still work from Jimp
|
||||
OtherCustomJimp.read("Test");
|
||||
|
||||
// Constants should not be applied to the static instance from ill-formed plugins
|
||||
// $ExpectError
|
||||
OtherCustomJimp.displace(OtherCustomJimp, 2);
|
||||
|
||||
// Methods should not be applied to the static instance from well-formed plugins
|
||||
// $ExpectError
|
||||
OtherCustomJimp.resize(40, 40);
|
||||
|
||||
// Constants should be applied from well-formed plugins
|
||||
OtherCustomJimp.RESIZE_NEAREST_NEIGHBOR;
|
||||
|
||||
// $ExpectError
|
||||
OtherCustomJimp.test;
|
||||
|
||||
// $ExpectError
|
||||
OtherCustomJimp.func();
|
||||
|
||||
const Jiimp = new OtherCustomJimp("test");
|
||||
// Methods from types should be applied
|
||||
Jiimp.deflateLevel(4);
|
||||
// Constants from types should not be applied to objects
|
||||
// $ExpectError
|
||||
Jiimp.PNG_FILTER_NONE;
|
||||
|
||||
// Methods from new plugins should be applied
|
||||
Jiimp.scale(3);
|
||||
|
||||
// Methods from types should be applied
|
||||
Jiimp.filterType(4);
|
||||
|
||||
// Core functions should still work from Jimp
|
||||
Jiimp.getPixelColor(1, 1);
|
||||
|
||||
// Constants should be applied from ill-formed plugins
|
||||
Jiimp.displace(Jiimp, 2);
|
||||
|
||||
// Methods should be applied from well-formed plugins
|
||||
Jiimp.resize(40, 40);
|
||||
|
||||
// Constants should not be applied from well-formed plugins to objects
|
||||
// $ExpectError
|
||||
Jiimp.RESIZE_NEAREST_NEIGHBOR;
|
||||
|
||||
// $ExpectError
|
||||
Jiimp.test;
|
||||
|
||||
// $ExpectError
|
||||
Jiimp.func();
|
||||
});
|
||||
|
||||
test("can handle only plugins", () => {
|
||||
const PluginsJimp = configure({
|
||||
plugins: [plugins],
|
||||
});
|
||||
|
||||
// Core functions should still work from Jimp
|
||||
PluginsJimp.read("Test");
|
||||
|
||||
// Constants should not be applied from ill-formed plugins
|
||||
// $ExpectError
|
||||
PluginsJimp.displace(PluginsJimp, 2);
|
||||
|
||||
// Methods should be not be applied to from well-formed plugins to the top level
|
||||
// $ExpectError
|
||||
PluginsJimp.resize(40, 40);
|
||||
|
||||
// Constants should be applied from well-formed plugins
|
||||
// $ExpectType "nearestNeighbor"
|
||||
PluginsJimp.RESIZE_NEAREST_NEIGHBOR;
|
||||
|
||||
// $ExpectError
|
||||
PluginsJimp.test;
|
||||
|
||||
// $ExpectError
|
||||
PluginsJimp.func();
|
||||
|
||||
const Jiimp = new PluginsJimp("test");
|
||||
|
||||
// Core functions should still work from Jimp
|
||||
Jiimp.getPixelColor(1, 1);
|
||||
|
||||
// Constants should be applied from ill-formed plugins
|
||||
Jiimp.displace(Jiimp, 2);
|
||||
|
||||
// Methods should be applied from well-formed plugins
|
||||
Jiimp.resize(40, 40);
|
||||
|
||||
// Constants should be not applied to objects from well-formed plugins
|
||||
// $ExpectError
|
||||
Jiimp.RESIZE_NEAREST_NEIGHBOR;
|
||||
|
||||
// $ExpectError
|
||||
Jiimp.test;
|
||||
|
||||
// $ExpectError
|
||||
Jiimp.func();
|
||||
});
|
||||
|
||||
test("can handle only all types", () => {
|
||||
const TypesJimp = configure({
|
||||
types: [types],
|
||||
});
|
||||
|
||||
// Methods from types should not be applied
|
||||
// $ExpectError
|
||||
TypesJimp.filterType(4);
|
||||
// Constants from types should be applied
|
||||
// $ExpectType 0
|
||||
TypesJimp.PNG_FILTER_NONE;
|
||||
|
||||
// $ExpectError
|
||||
TypesJimp.test;
|
||||
|
||||
// $ExpectError
|
||||
TypesJimp.func();
|
||||
|
||||
const Jiimp = new TypesJimp("test");
|
||||
// Methods from types should be applied
|
||||
Jiimp.filterType(4);
|
||||
// Constants from types should be not applied to objects
|
||||
// $ExpectError
|
||||
Jiimp.PNG_FILTER_NONE;
|
||||
|
||||
// $ExpectError
|
||||
Jiimp.test;
|
||||
|
||||
// $ExpectError
|
||||
Jiimp.func();
|
||||
});
|
||||
|
||||
test("can handle only one type", () => {
|
||||
const PngJimp = configure({
|
||||
types: [png],
|
||||
});
|
||||
|
||||
// Constants from other types should be not applied
|
||||
// $ExpectError
|
||||
PngJimp.MIME_TIFF;
|
||||
|
||||
// Constants from types should be applied
|
||||
// $ExpectType 0
|
||||
PngJimp.PNG_FILTER_NONE;
|
||||
|
||||
// $ExpectError
|
||||
PngJimp.test;
|
||||
|
||||
// $ExpectError
|
||||
PngJimp.func();
|
||||
|
||||
const Jiimp = new PngJimp("test");
|
||||
// Constants from other types should be not applied
|
||||
// $ExpectError
|
||||
Jiimp.MIME_TIFF;
|
||||
|
||||
// Constants from types should not be applied to objects
|
||||
// $ExpectError
|
||||
Jiimp.PNG_FILTER_NONE;
|
||||
|
||||
// $ExpectError
|
||||
Jiimp.test;
|
||||
|
||||
// $ExpectError
|
||||
Jiimp.func();
|
||||
});
|
||||
|
||||
test("can handle only one plugin", () => {
|
||||
const ResizeJimp = configure({
|
||||
plugins: [resize],
|
||||
});
|
||||
|
||||
// Constants from other plugins should be not applied
|
||||
// $ExpectError
|
||||
ResizeJimp.FONT_SANS_8_BLACK;
|
||||
|
||||
// Constants from plugin should be applied
|
||||
// $ExpectType "nearestNeighbor"
|
||||
ResizeJimp.RESIZE_NEAREST_NEIGHBOR;
|
||||
|
||||
// $ExpectError
|
||||
ResizeJimp.resize(2, 2);
|
||||
|
||||
// $ExpectError
|
||||
ResizeJimp.test;
|
||||
|
||||
// $ExpectError
|
||||
ResizeJimp.func();
|
||||
|
||||
const Jiimp: InstanceType<typeof ResizeJimp> = new ResizeJimp("test");
|
||||
// Constants from other plugins should be not applied
|
||||
// $ExpectError
|
||||
Jiimp.FONT_SANS_8_BLACK;
|
||||
|
||||
// Constants from plugin should not be applied to the object
|
||||
// $ExpectError
|
||||
Jiimp.RESIZE_NEAREST_NEIGHBOR;
|
||||
|
||||
Jiimp.resize(2, 2);
|
||||
|
||||
// $ExpectError
|
||||
Jiimp.test;
|
||||
|
||||
// $ExpectError
|
||||
Jiimp.func();
|
||||
});
|
||||
|
||||
test("Can handle appendConstructorOption", () => {
|
||||
const AppendJimp = configure({});
|
||||
|
||||
AppendJimp.appendConstructorOption(
|
||||
"Name of Option",
|
||||
(args) => args.hasSomeCustomThing,
|
||||
function (resolve, reject, args) {
|
||||
// $ExpectError
|
||||
this.bitmap = 3;
|
||||
// $ExpectError
|
||||
AppendJimp.resize(2, 2);
|
||||
resolve();
|
||||
}
|
||||
);
|
||||
});
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"skipLibCheck": true,
|
||||
"noEmit": true,
|
||||
|
||||
// If the library is an external module (uses `export`), this allows your test file to import "mylib" instead of "./index".
|
||||
// If the library is global (cannot be imported via `import` or `require`), leave this out.
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"mylib": ["."]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user