@pi-r/jimp 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +6 -6
- package/README.md +6 -6
- package/index.js +14 -13
- package/package.json +29 -29
- package/types/index.d.ts +19 -18
- package/util.d.ts +9 -9
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
3
|
-
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:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
3
|
+
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:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
7
|
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.
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
### @pi-r/jimp
|
|
2
|
-
|
|
3
|
-
https://e-mc.readthedocs.io/en/latest/image
|
|
4
|
-
|
|
5
|
-
### LICENSE
|
|
6
|
-
|
|
1
|
+
### @pi-r/jimp
|
|
2
|
+
|
|
3
|
+
https://e-mc.readthedocs.io/en/latest/image
|
|
4
|
+
|
|
5
|
+
### LICENSE
|
|
6
|
+
|
|
7
7
|
MIT
|
package/index.js
CHANGED
|
@@ -67,17 +67,17 @@ const METHOD_ALIAS = {
|
|
|
67
67
|
threshold: 'th'
|
|
68
68
|
};
|
|
69
69
|
function getMethodName(value) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return name;
|
|
73
|
-
}
|
|
74
|
-
if (name.length === 2) {
|
|
70
|
+
if (value.length === 2) {
|
|
71
|
+
value = value.toLowerCase();
|
|
75
72
|
for (const alias in METHOD_ALIAS) {
|
|
76
|
-
if (METHOD_ALIAS[alias] ===
|
|
73
|
+
if (METHOD_ALIAS[alias] === value) {
|
|
77
74
|
return alias;
|
|
78
75
|
}
|
|
79
76
|
}
|
|
80
77
|
}
|
|
78
|
+
else if (METHOD_ALIAS[value] || METHOD_ALIAS[value = value.toLowerCase()]) {
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
81
|
}
|
|
82
82
|
async function performCommand(host, instance, localUri, command, outputType, finalAs, buffer, parent) {
|
|
83
83
|
return jimp.read((buffer || localUri))
|
|
@@ -119,9 +119,9 @@ async function transformCommand(localFile, handler, command, outputType, outputA
|
|
|
119
119
|
return handler.rotate();
|
|
120
120
|
default:
|
|
121
121
|
return handler.rotate(localFile, (err, result) => {
|
|
122
|
-
if (!err
|
|
122
|
+
if (!err) {
|
|
123
123
|
try {
|
|
124
|
-
handler.host
|
|
124
|
+
handler.host?.add(result, parent);
|
|
125
125
|
}
|
|
126
126
|
catch {
|
|
127
127
|
}
|
|
@@ -232,12 +232,10 @@ function getTempPath(ext) {
|
|
|
232
232
|
}
|
|
233
233
|
const removeFile = (pathname) => fs.unlink(pathname, () => { });
|
|
234
234
|
class JimpHandler {
|
|
235
|
-
handler;
|
|
236
|
-
instance;
|
|
237
|
-
_host = null;
|
|
238
235
|
constructor(handler, instance, host) {
|
|
239
236
|
this.handler = handler;
|
|
240
237
|
this.instance = instance;
|
|
238
|
+
this._host = null;
|
|
241
239
|
if (host) {
|
|
242
240
|
this._host = host;
|
|
243
241
|
}
|
|
@@ -562,6 +560,11 @@ class JimpHandler {
|
|
|
562
560
|
}
|
|
563
561
|
}
|
|
564
562
|
class Jimp extends Image {
|
|
563
|
+
constructor() {
|
|
564
|
+
super(...arguments);
|
|
565
|
+
this._moduleName = "jimp";
|
|
566
|
+
this._threadable = true;
|
|
567
|
+
}
|
|
565
568
|
static async transform(file, command, options = {}) {
|
|
566
569
|
const [outputType, saveAs, finalAs] = (0, util_1.parseFormat)(command = command.trim(), options.mimeType);
|
|
567
570
|
const empty = () => options.tempFile ? '' : null;
|
|
@@ -627,8 +630,6 @@ class Jimp extends Image {
|
|
|
627
630
|
.catch(() => empty())
|
|
628
631
|
.finally(() => buffer && !options.cache && removeFile(file));
|
|
629
632
|
}
|
|
630
|
-
_moduleName = "jimp";
|
|
631
|
-
_threadable = true;
|
|
632
633
|
parseRotate(value) {
|
|
633
634
|
const data = super.parseRotate(value);
|
|
634
635
|
if (data && this.settings.jimp?.rotate_clockwise) {
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pi-r/jimp",
|
|
3
|
-
"version": "0.7.
|
|
4
|
-
"description": "Jimp image constructor for E-mc.",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"access": "public"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
|
-
"directory": "src/module/jimp"
|
|
13
|
-
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"squared",
|
|
16
|
-
"e-mc",
|
|
17
|
-
"squared-functions"
|
|
18
|
-
],
|
|
19
|
-
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@e-mc/image": "^0.9.
|
|
24
|
-
"@e-mc/types": "^0.9.
|
|
25
|
-
"bmp-js": "^0.1.0",
|
|
26
|
-
"gifwrap": "^0.10.1",
|
|
27
|
-
"jimp": "^0.22.12"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-r/jimp",
|
|
3
|
+
"version": "0.7.5",
|
|
4
|
+
"description": "Jimp image constructor for E-mc.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
|
+
"directory": "src/module/jimp"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"squared",
|
|
16
|
+
"e-mc",
|
|
17
|
+
"squared-functions"
|
|
18
|
+
],
|
|
19
|
+
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@e-mc/image": "^0.9.18",
|
|
24
|
+
"@e-mc/types": "^0.9.18",
|
|
25
|
+
"bmp-js": "^0.1.0",
|
|
26
|
+
"gifwrap": "^0.10.1",
|
|
27
|
+
"jimp": "^0.22.12"
|
|
28
|
+
}
|
|
29
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import type { IHost, IImage, ImageConstructor } from '@e-mc/types/lib';
|
|
2
|
-
import type { ImageModule } from '@e-mc/types/lib/settings';
|
|
3
|
-
|
|
4
|
-
import type { ImageHandler } from '@e-mc/image/types';
|
|
5
|
-
|
|
6
|
-
import type * as jimp from 'jimp';
|
|
7
|
-
|
|
8
|
-
export interface IJimpHandler<T extends IHost = IHost, U extends ImageModule = ImageModule> extends ImageHandler<jimp, T, IImage<T, U>> {
|
|
9
|
-
method(): Promise<void>;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import type { IHost, IImage, ImageConstructor } from '@e-mc/types/lib';
|
|
2
|
+
import type { ImageModule } from '@e-mc/types/lib/settings';
|
|
3
|
+
|
|
4
|
+
import type { ImageHandler } from '@e-mc/image/types';
|
|
5
|
+
|
|
6
|
+
import type * as jimp from 'jimp';
|
|
7
|
+
|
|
8
|
+
export interface IJimpHandler<T extends IHost = IHost, U extends ImageModule = ImageModule> extends ImageHandler<jimp, T, IImage<T, U>> {
|
|
9
|
+
method(): Promise<void>;
|
|
10
|
+
quality(): void;
|
|
11
|
+
rotate(localFile?: string, callback?: ResultCallback<string>): Promise<this>;
|
|
12
|
+
background(value: number | [number, number, number, number]): void;
|
|
13
|
+
writeAsync(output: string, callback?: ResultCallback): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface JimpImageConstructor extends ImageConstructor {
|
|
17
|
+
new(handler: jimp, instance: IImage, host?: Null<IHost>): IJimpHandler;
|
|
18
|
+
}
|
|
19
|
+
|
|
19
20
|
export type ResultCallback<T = unknown, U = void, V = unknown> = (err: V, result: T) => U;
|
package/util.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
declare namespace util {
|
|
2
|
-
function parseFormat(command: string, mimeType?: string, gif?: boolean): [string, string, string];
|
|
3
|
-
function renameExt(output: string, ext: string, replace?: boolean): string;
|
|
4
|
-
function normalizePath(value: string): string;
|
|
5
|
-
function getWebP_bin(name: string, pathname: string | undefined): string;
|
|
6
|
-
function showInputType(value: string | undefined, outputType: string, finalAs: string): string;
|
|
7
|
-
function showOutputType(value: string | undefined, outputType: string, finalAs: string): string;
|
|
8
|
-
}
|
|
9
|
-
|
|
1
|
+
declare namespace util {
|
|
2
|
+
function parseFormat(command: string, mimeType?: string, gif?: boolean): [string, string, string];
|
|
3
|
+
function renameExt(output: string, ext: string, replace?: boolean): string;
|
|
4
|
+
function normalizePath(value: string): string;
|
|
5
|
+
function getWebP_bin(name: string, pathname: string | undefined): string;
|
|
6
|
+
function showInputType(value: string | undefined, outputType: string, finalAs: string): string;
|
|
7
|
+
function showOutputType(value: string | undefined, outputType: string, finalAs: string): string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
10
|
export = util;
|