@thi.ng/imago 0.3.1 → 0.4.0
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/CHANGELOG.md +7 -1
- package/README.md +12 -4
- package/api.d.ts +9 -0
- package/ops/output.js +21 -2
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-02-
|
|
3
|
+
- **Last updated**: 2024-02-27T20:35:06Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [0.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/imago@0.4.0) (2024-02-27)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add blurhash output option, update deps ([b7ffedd](https://github.com/thi-ng/umbrella/commit/b7ffedd))
|
|
17
|
+
|
|
12
18
|
## [0.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/imago@0.3.0) (2024-02-23)
|
|
13
19
|
|
|
14
20
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -76,9 +76,10 @@ The following pipeline performs these steps (in sequence):
|
|
|
76
76
|
- proportionally resize image to 1920px (longest side by default)
|
|
77
77
|
- overlay bitmap logo layer, positioned at 45% left / 5% bottom
|
|
78
78
|
- add custom EXIF metadata
|
|
79
|
-
- output this current stage as high quality AVIF (
|
|
79
|
+
- output this current stage as high quality AVIF (and record expanded output path)
|
|
80
80
|
- crop center square region
|
|
81
|
-
- output as JPEG thumbnail
|
|
81
|
+
- output as JPEG thumbnail (and record in outputs)
|
|
82
|
+
- compute [blurhash](https://github.com/thi-ng/umbrella/blob/develop/packages/blurhash) (and record in outputs)
|
|
82
83
|
|
|
83
84
|
```json tangle:export/readme-example1.json
|
|
84
85
|
[
|
|
@@ -113,7 +114,8 @@ The following pipeline performs these steps (in sequence):
|
|
|
113
114
|
"avif": { "quality": 80 }
|
|
114
115
|
},
|
|
115
116
|
{ "op": "crop", "size": [240, 240], "gravity": "c" },
|
|
116
|
-
{ "op": "output", "id": "thumb", "path": "{name}-thumb.jpg" }
|
|
117
|
+
{ "op": "output", "id": "thumb", "path": "{name}-thumb.jpg" },
|
|
118
|
+
{ "op": "output", "id": "hash", "path": "", blurhash: { detail: 4 } }
|
|
117
119
|
]
|
|
118
120
|
```
|
|
119
121
|
|
|
@@ -232,6 +234,11 @@ File output in any of these formats:
|
|
|
232
234
|
- tiff
|
|
233
235
|
- webp
|
|
234
236
|
|
|
237
|
+
Alternatively, a
|
|
238
|
+
[blurhash](https://github.com/thi-ng/umbrella/blob/develop/packages/blurhash) of
|
|
239
|
+
the image can be computed and stored in the outputs. In this case, no file will
|
|
240
|
+
be written.
|
|
241
|
+
|
|
235
242
|
#### Templated output paths
|
|
236
243
|
|
|
237
244
|
Output paths can contain `{id}`-templated parts which will be replaced/expanded.
|
|
@@ -302,12 +309,13 @@ For Node.js REPL:
|
|
|
302
309
|
const imago = await import("@thi.ng/imago");
|
|
303
310
|
```
|
|
304
311
|
|
|
305
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 4.
|
|
312
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 4.16 KB
|
|
306
313
|
|
|
307
314
|
## Dependencies
|
|
308
315
|
|
|
309
316
|
- [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
|
|
310
317
|
- [@thi.ng/associative](https://github.com/thi-ng/umbrella/tree/develop/packages/associative)
|
|
318
|
+
- [@thi.ng/blurhash](https://github.com/thi-ng/umbrella/tree/develop/packages/blurhash)
|
|
311
319
|
- [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
|
|
312
320
|
- [@thi.ng/date](https://github.com/thi-ng/umbrella/tree/develop/packages/date)
|
|
313
321
|
- [@thi.ng/defmulti](https://github.com/thi-ng/umbrella/tree/develop/packages/defmulti)
|
package/api.d.ts
CHANGED
|
@@ -129,6 +129,15 @@ export interface OutputSpec extends ProcSpec {
|
|
|
129
129
|
*/
|
|
130
130
|
path: string;
|
|
131
131
|
avif?: AvifOptions;
|
|
132
|
+
blurhash?: {
|
|
133
|
+
/**
|
|
134
|
+
* Blurhash detail setting in 1-9 range, possibly given separately for
|
|
135
|
+
* X/Y axis.
|
|
136
|
+
*
|
|
137
|
+
* @defaultValue 4
|
|
138
|
+
*/
|
|
139
|
+
detail?: number | [number, number];
|
|
140
|
+
};
|
|
132
141
|
gif?: GifOptions;
|
|
133
142
|
jp2?: Jp2Options;
|
|
134
143
|
jpeg?: JpegOptions;
|
package/ops/output.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import { encode } from "@thi.ng/blurhash";
|
|
1
2
|
import { writeFile, writeJSON } from "@thi.ng/file-io";
|
|
2
3
|
import { join, resolve } from "node:path";
|
|
3
4
|
import { formatPath } from "../path.js";
|
|
4
|
-
import { isPlainObject } from "@thi.ng/checks";
|
|
5
|
+
import { isNumber, isPlainObject } from "@thi.ng/checks";
|
|
5
6
|
const outputProc = async (spec, input, ctx) => {
|
|
6
7
|
const opts = spec;
|
|
7
8
|
const outDir = resolve(ctx.opts.outDir || ".");
|
|
8
9
|
let output = input.clone();
|
|
10
|
+
if (opts.blurhash) {
|
|
11
|
+
await outputBlurHash(opts, output, ctx);
|
|
12
|
+
return [input, false];
|
|
13
|
+
}
|
|
9
14
|
if (opts.raw) {
|
|
10
15
|
await outputRaw(opts, output, ctx, outDir);
|
|
11
16
|
return [input, false];
|
|
@@ -76,7 +81,7 @@ const outputRaw = async (opts, output, ctx, outDir) => {
|
|
|
76
81
|
const { alpha = false, meta = false } = isPlainObject(opts.raw) ? opts.raw : {};
|
|
77
82
|
if (alpha)
|
|
78
83
|
output = output.ensureAlpha();
|
|
79
|
-
const { data, info } = await output.raw().toBuffer({ resolveWithObject: true });
|
|
84
|
+
const { data, info } = await output.ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
80
85
|
const path = join(outDir, formatPath(opts.path, ctx, opts, data));
|
|
81
86
|
writeFile(path, data, null, ctx.logger);
|
|
82
87
|
ctx.outputs[opts.id] = path;
|
|
@@ -90,6 +95,20 @@ const outputRaw = async (opts, output, ctx, outDir) => {
|
|
|
90
95
|
);
|
|
91
96
|
}
|
|
92
97
|
};
|
|
98
|
+
const outputBlurHash = async (opts, output, ctx) => {
|
|
99
|
+
const { data, info } = await output.ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
100
|
+
const detail = opts.blurhash.detail || 4;
|
|
101
|
+
const [dx, dy] = isNumber(detail) ? [detail, detail] : detail;
|
|
102
|
+
const hash = encode(
|
|
103
|
+
new Uint32Array(data.buffer),
|
|
104
|
+
info.width,
|
|
105
|
+
info.height,
|
|
106
|
+
dx,
|
|
107
|
+
dy
|
|
108
|
+
);
|
|
109
|
+
ctx.outputs[opts.id] = hash;
|
|
110
|
+
ctx.logger.debug("computed blurhash:", hash);
|
|
111
|
+
};
|
|
93
112
|
export {
|
|
94
113
|
outputProc
|
|
95
114
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/imago",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "JSON & API-based declarative and extensible image processing trees/pipelines",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@thi.ng/api": "^8.9.26",
|
|
39
39
|
"@thi.ng/associative": "^6.3.43",
|
|
40
|
+
"@thi.ng/blurhash": "^0.1.11",
|
|
40
41
|
"@thi.ng/checks": "^3.5.0",
|
|
41
42
|
"@thi.ng/date": "^2.7.1",
|
|
42
43
|
"@thi.ng/defmulti": "^3.0.26",
|
|
@@ -125,5 +126,5 @@
|
|
|
125
126
|
"status": "alpha",
|
|
126
127
|
"year": 2024
|
|
127
128
|
},
|
|
128
|
-
"gitHead": "
|
|
129
|
+
"gitHead": "41860743a21093aa13b6b7f4e36cd5e2e934d159\n"
|
|
129
130
|
}
|