@e-mc/image 0.0.1

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/jimp/util.d.ts ADDED
@@ -0,0 +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
+
10
+ export = util;
package/jimp/util.js ADDED
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.showOutputType = exports.showInputType = exports.getWebP_bin = exports.normalizePath = exports.renameExt = exports.parseFormat = exports.MIME_OUTPUT = exports.MIME_INPUT = void 0;
4
+ const path = require("path");
5
+ const fs = require("fs");
6
+ const jimp = require("jimp");
7
+ const types_1 = require("../../types");
8
+ const index_1 = require("../index");
9
+ exports.MIME_INPUT = new Set([jimp.MIME_PNG, jimp.MIME_JPEG, jimp.MIME_BMP, jimp.MIME_GIF, jimp.MIME_TIFF, "image/webp" /* STRINGS.MIME_WEBP */]);
10
+ exports.MIME_OUTPUT = new Set([jimp.MIME_PNG, jimp.MIME_JPEG, jimp.MIME_BMP, jimp.MIME_GIF, "image/webp" /* STRINGS.MIME_WEBP */]);
11
+ function parseFormat(command, mimeType, gif) {
12
+ command = command.toLowerCase();
13
+ for (let mime of exports.MIME_OUTPUT) {
14
+ let saveAs = mime.split('/')[1];
15
+ if (command.startsWith(saveAs)) {
16
+ let finalAs = '';
17
+ if (saveAs !== 'gif') {
18
+ switch (saveAs) {
19
+ case 'jpeg':
20
+ saveAs = 'jpg';
21
+ break;
22
+ case 'webp':
23
+ if (mimeType === "image/webp" /* STRINGS.MIME_WEBP */) {
24
+ try {
25
+ require('node-webpmux');
26
+ mime = "image/webp" /* STRINGS.MIME_WEBP */;
27
+ break;
28
+ }
29
+ catch {
30
+ }
31
+ }
32
+ if (mimeType === jimp.MIME_JPEG) {
33
+ mime = jimp.MIME_JPEG;
34
+ saveAs = 'jpg';
35
+ }
36
+ else if (gif && mimeType === jimp.MIME_GIF) {
37
+ mime = jimp.MIME_GIF;
38
+ saveAs = 'gif';
39
+ }
40
+ else {
41
+ mime = jimp.MIME_PNG;
42
+ saveAs = 'png';
43
+ }
44
+ finalAs = 'webp';
45
+ break;
46
+ }
47
+ }
48
+ else if (!gif) {
49
+ break;
50
+ }
51
+ return [mime, saveAs, finalAs];
52
+ }
53
+ }
54
+ return ['', '', ''];
55
+ }
56
+ exports.parseFormat = parseFormat;
57
+ function renameExt(output, ext, replace) {
58
+ let result = (0, types_1.renameExt)(output.replace('.__copy__.', '.'), ext);
59
+ if (!replace) {
60
+ const pathname = result;
61
+ let i = 0;
62
+ while (index_1.default.isPath(result)) {
63
+ result = pathname.substring(0, pathname.lastIndexOf('.') + 1) + `(${++i}).` + ext;
64
+ }
65
+ }
66
+ return result;
67
+ }
68
+ exports.renameExt = renameExt;
69
+ function normalizePath(value) {
70
+ return '"' + value.replace(/"/g, '\\"') + '"';
71
+ }
72
+ exports.normalizePath = normalizePath;
73
+ function getWebP_bin(name, pathname) {
74
+ if (pathname && fs.existsSync(pathname)) {
75
+ name += process.platform === 'win32' ? '.exe' : '';
76
+ const bin = path.join(pathname, name);
77
+ return index_1.default.sanitizeCmd(fs.existsSync(bin) ? bin : path.join(pathname, 'bin', name));
78
+ }
79
+ return require(name + '-bin');
80
+ }
81
+ exports.getWebP_bin = getWebP_bin;
82
+ function showInputType(value, outputType, finalAs) {
83
+ if (finalAs) {
84
+ outputType = 'image/' + finalAs;
85
+ }
86
+ return value && outputType !== value ? value.split('/').pop() + ' -> ' : '';
87
+ }
88
+ exports.showInputType = showInputType;
89
+ function showOutputType(value, outputType, finalAs) {
90
+ if (finalAs) {
91
+ outputType = 'image/' + finalAs;
92
+ }
93
+ return value !== outputType ? ' -> ' + outputType.split('/').pop() : '';
94
+ }
95
+ exports.showOutputType = showOutputType;
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@e-mc/image",
3
+ "version": "0.0.1",
4
+ "description": "Image constructor for e-mc.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/anpham6/e-mc.git",
13
+ "directory": "src/image"
14
+ },
15
+ "keywords": [
16
+ "squared",
17
+ "squared-functions"
18
+ ],
19
+ "author": "An Pham <anpham6@gmail.com>",
20
+ "license": "BSD 3-Clause",
21
+ "homepage": "https://github.com/anpham6/e-mc#readme",
22
+ "dependencies": {
23
+ "@e-mc/core": "0.0.1",
24
+ "bmp-js": "^0.1.0",
25
+ "jimp": "^0.22.7"
26
+ }
27
+ }
@@ -0,0 +1,38 @@
1
+ export interface ImageHandler<T, U, V> {
2
+ readonly handler: T;
3
+ host: U | null;
4
+ instance: V;
5
+ method(): void;
6
+ resize(): void;
7
+ crop(): void;
8
+ opacity(): void;
9
+ quality(): void;
10
+ rotate(...args: unknown[]): unknown;
11
+ background?(value: unknown): void;
12
+ write(output: string, callback?: (err: unknown, result: string) => void): void;
13
+ getBuffer(tempFile?: boolean, saveAs?: string): Promise<string | Buffer | null>;
14
+ finalize(output: string, callback: (err: unknown, result: string) => void): void;
15
+ get rotateCount(): number;
16
+ get aborted(): boolean;
17
+ }
18
+
19
+ export interface WebpMuxFrame extends Dimension, Point {
20
+ delay: number;
21
+ }
22
+
23
+ export interface WebpMuxImage extends Readonly<Dimension> {
24
+ readonly anim: { loops: number; bgColor: [number, number, number, number] };
25
+ initLib(): Promise<void>;
26
+ load(value: BufferContent): Promise<void>;
27
+ demux(options: { path?: string; prefix?: string; buffers?: boolean }): Promise<void>;
28
+ getImageData(): Promise<Uint8Array>;
29
+ getFrameData(frame: number): Promise<Uint8Array>;
30
+ setFrameData(frame: number, source: Buffer, options: Dimension & { preset?: string; quality?: number; exact?: boolean; lossless?: number; method?: number }): Promise<void>;
31
+ save(path: string, options: Dimension & { bgColor?: number[] }): Promise<void>;
32
+ get hasAnim(): boolean;
33
+ get frames(): WebpMuxFrame[];
34
+ }
35
+
36
+ export interface WebpMux {
37
+ Image: new() => WebpMuxImage;
38
+ }