@thi.ng/imago 0.1.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 +21 -0
- package/LICENSE +201 -0
- package/README.md +291 -0
- package/api.d.ts +161 -0
- package/api.js +26 -0
- package/index.d.ts +6 -0
- package/index.js +5 -0
- package/ops.d.ts +16 -0
- package/ops.js +30 -0
- package/package.json +125 -0
- package/path.d.ts +22 -0
- package/path.js +34 -0
- package/proc.d.ts +27 -0
- package/proc.js +362 -0
- package/units.d.ts +24 -0
- package/units.js +85 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
- **Last updated**: 2024-02-22T11:59:16Z
|
|
4
|
+
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
|
+
|
|
6
|
+
All notable changes to this project will be documented in this file.
|
|
7
|
+
See [Conventional Commits](https://conventionalcommits.org/) for commit guidelines.
|
|
8
|
+
|
|
9
|
+
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
|
+
and/or version bumps of transitive dependencies.
|
|
11
|
+
|
|
12
|
+
## [0.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/imago@0.1.0) (2024-02-22)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- import as new pkg ([66b62ff](https://github.com/thi-ng/umbrella/commit/66b62ff))
|
|
17
|
+
- add output path formatters, restructure pkg ([0b06527](https://github.com/thi-ng/umbrella/commit/0b06527))
|
|
18
|
+
|
|
19
|
+
#### ♻️ Refactoring
|
|
20
|
+
|
|
21
|
+
- update all `node:*` imports ([c71a526](https://github.com/thi-ng/umbrella/commit/c71a526))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
<!-- This file is generated - DO NOT EDIT! -->
|
|
2
|
+
<!-- Please see: https://github.com/thi-ng/umbrella/blob/develop/CONTRIBUTING.md#changes-to-readme-files -->
|
|
3
|
+
> [!IMPORTANT]
|
|
4
|
+
> ‼️ Announcing the thi.ng user survey 2024 📋
|
|
5
|
+
>
|
|
6
|
+
> [Please participate in the survey here!](https://forms.gle/XacbSDEmQMPZg8197)\
|
|
7
|
+
> (open until end of February)
|
|
8
|
+
>
|
|
9
|
+
> **To achieve a better sample size, I'd highly appreciate if you could
|
|
10
|
+
> circulate the link to this survey in your own networks.**
|
|
11
|
+
>
|
|
12
|
+
> [Discussion](https://github.com/thi-ng/umbrella/discussions/447)
|
|
13
|
+
|
|
14
|
+
# 
|
|
15
|
+
|
|
16
|
+
[](https://www.npmjs.com/package/@thi.ng/imago)
|
|
17
|
+

|
|
18
|
+
[](https://mastodon.thi.ng/@toxi)
|
|
19
|
+
|
|
20
|
+
> [!NOTE]
|
|
21
|
+
> This is one of 190 standalone projects, maintained as part
|
|
22
|
+
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
23
|
+
> and anti-framework.
|
|
24
|
+
>
|
|
25
|
+
> 🚀 Help me to work full-time on these projects by [sponsoring me on
|
|
26
|
+
> GitHub](https://github.com/sponsors/postspectacular). Thank you! ❤️
|
|
27
|
+
|
|
28
|
+
- [About](#about)
|
|
29
|
+
- [Basic example](#basic-example)
|
|
30
|
+
- [Supported operations](#supported-operations)
|
|
31
|
+
- [blur](#blur)
|
|
32
|
+
- [composite](#composite)
|
|
33
|
+
- [Common options](#common-options)
|
|
34
|
+
- [Bitmap layers](#bitmap-layers)
|
|
35
|
+
- [SVG layers](#svg-layers)
|
|
36
|
+
- [crop](#crop)
|
|
37
|
+
- [dither](#dither)
|
|
38
|
+
- [exif](#exif)
|
|
39
|
+
- [extend](#extend)
|
|
40
|
+
- [gamma](#gamma)
|
|
41
|
+
- [grayscale](#grayscale)
|
|
42
|
+
- [hsbl](#hsbl)
|
|
43
|
+
- [nest](#nest)
|
|
44
|
+
- [output](#output)
|
|
45
|
+
- [resize](#resize)
|
|
46
|
+
- [rotate](#rotate)
|
|
47
|
+
- [Status](#status)
|
|
48
|
+
- [Installation](#installation)
|
|
49
|
+
- [Dependencies](#dependencies)
|
|
50
|
+
- [API](#api)
|
|
51
|
+
- [Authors](#authors)
|
|
52
|
+
- [License](#license)
|
|
53
|
+
|
|
54
|
+
## About
|
|
55
|
+
|
|
56
|
+
JSON & API-based declarative and extensible image processing trees/pipelines.
|
|
57
|
+
|
|
58
|
+
Spiritual successor of an eponymous, yet never fully published
|
|
59
|
+
CLojure/Java-based image processor from 2014...
|
|
60
|
+
|
|
61
|
+
In this new TypeScript version all image I/O and processing is delegated to
|
|
62
|
+
[sharp](https://sharp.pixelplumbing.com) and
|
|
63
|
+
[@thi.ng/pixel](https://github.com/thi-ng/umbrella/blob/develop/packages/pixel).
|
|
64
|
+
|
|
65
|
+
### Basic example
|
|
66
|
+
|
|
67
|
+
Transformation trees/pipelines are simple JSON objects (but can be programmatically created):
|
|
68
|
+
|
|
69
|
+
The following pipeline performs the following steps:
|
|
70
|
+
|
|
71
|
+
- auto-rotate image (using EXIF orientation info)
|
|
72
|
+
- add 5% white border (size relative to shortest side)
|
|
73
|
+
- proportionally resize to 1920px (by default longest side)
|
|
74
|
+
- overlay bitmap logo layer, positioned at 45% left / 5% bottom
|
|
75
|
+
- add custom EXIF metadata
|
|
76
|
+
- output this current stage as high quality AVIF (using templated output path)
|
|
77
|
+
- crop center square region
|
|
78
|
+
- output as JPEG thumbnail
|
|
79
|
+
|
|
80
|
+
```json tangle:export/readme-example1.json
|
|
81
|
+
[
|
|
82
|
+
{ "type": "rotate" },
|
|
83
|
+
{ "type": "extend", "border": 5, "unit": "%", "ref": "min", "bg": "#fff" },
|
|
84
|
+
{ "type": "resize", "size": 1920 },
|
|
85
|
+
{
|
|
86
|
+
"type": "composite",
|
|
87
|
+
"layers": [
|
|
88
|
+
{
|
|
89
|
+
"type": "img",
|
|
90
|
+
"path": "logo-128.png",
|
|
91
|
+
"pos": { "l": 45, "b": 5 },
|
|
92
|
+
"unit": "%",
|
|
93
|
+
"blend": "screen"
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"type": "exif",
|
|
99
|
+
"tags": {
|
|
100
|
+
"IFD0": {
|
|
101
|
+
"Copyright": "Karsten Schmidt",
|
|
102
|
+
"Software": "@thi.ng/imago"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"type": "output",
|
|
108
|
+
"path": "{name}-{sha256}-{w}x{h}.avif",
|
|
109
|
+
"avif": { "quality": 80 }
|
|
110
|
+
},
|
|
111
|
+
{ "type": "crop", "size": [240, 240], "gravity": "c" },
|
|
112
|
+
{ "type": "output", "path": "{name}-thumb.jpg" }
|
|
113
|
+
]
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Then to process an image:
|
|
117
|
+
|
|
118
|
+
```ts tangle:export/readme1.ts
|
|
119
|
+
import { processImage } from "@thi.ng/imago";
|
|
120
|
+
import { readJSON } from "@thi.ng/file-io";
|
|
121
|
+
|
|
122
|
+
await processImage(
|
|
123
|
+
"test.jpg",
|
|
124
|
+
readJSON("readme-example1.json"),
|
|
125
|
+
{ outDir: "." }
|
|
126
|
+
);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Supported operations
|
|
130
|
+
|
|
131
|
+
TODO write docs
|
|
132
|
+
|
|
133
|
+
### blur
|
|
134
|
+
|
|
135
|
+
Gaussian blur
|
|
136
|
+
|
|
137
|
+
- radius
|
|
138
|
+
|
|
139
|
+
### composite
|
|
140
|
+
|
|
141
|
+
Compositing multiple layers:
|
|
142
|
+
|
|
143
|
+
#### Common options
|
|
144
|
+
|
|
145
|
+
- blend mode
|
|
146
|
+
- gravity or position
|
|
147
|
+
- tiled repetition
|
|
148
|
+
|
|
149
|
+
#### Bitmap layers
|
|
150
|
+
|
|
151
|
+
- resizable
|
|
152
|
+
|
|
153
|
+
#### SVG layers
|
|
154
|
+
|
|
155
|
+
- from file or inline doc
|
|
156
|
+
|
|
157
|
+
### crop
|
|
158
|
+
|
|
159
|
+
Cropping a part of the image
|
|
160
|
+
|
|
161
|
+
- from edges or region
|
|
162
|
+
- supports px or percent units
|
|
163
|
+
- proportional to a given reference side/size
|
|
164
|
+
|
|
165
|
+
### dither
|
|
166
|
+
|
|
167
|
+
Supported dither modes from
|
|
168
|
+
[thi.ng/pixel-dither](https://github.com/thi-ng/umbrella/blob/develop/packages/pixel-dither):
|
|
169
|
+
|
|
170
|
+
- "atkinson"
|
|
171
|
+
- "burkes"
|
|
172
|
+
- "column"
|
|
173
|
+
- "diffusion"
|
|
174
|
+
- "floyd"
|
|
175
|
+
- "jarvis"
|
|
176
|
+
- "row"
|
|
177
|
+
- "sierra"
|
|
178
|
+
- "stucki"
|
|
179
|
+
|
|
180
|
+
### exif
|
|
181
|
+
|
|
182
|
+
Set EXIF metadata (can only be given directly before [output](#output))
|
|
183
|
+
|
|
184
|
+
### extend
|
|
185
|
+
|
|
186
|
+
Add pixels on all sides of the image
|
|
187
|
+
|
|
188
|
+
- supports px or percent units
|
|
189
|
+
- proportional to a given reference side/size
|
|
190
|
+
|
|
191
|
+
### gamma
|
|
192
|
+
|
|
193
|
+
Perform gamma correction (forward or reverse)
|
|
194
|
+
|
|
195
|
+
### grayscale
|
|
196
|
+
|
|
197
|
+
Grayscale conversion
|
|
198
|
+
|
|
199
|
+
### hsbl
|
|
200
|
+
|
|
201
|
+
Hue, saturation, brightness and lightness adjustments
|
|
202
|
+
|
|
203
|
+
### nest
|
|
204
|
+
|
|
205
|
+
Nested branch/pipeline of operations with no effect on image state of
|
|
206
|
+
current/parent pipeline...
|
|
207
|
+
|
|
208
|
+
### output
|
|
209
|
+
|
|
210
|
+
File output in any of these formats:
|
|
211
|
+
|
|
212
|
+
- avif
|
|
213
|
+
- gif
|
|
214
|
+
- jpeg
|
|
215
|
+
- jp2 (JPEG 2000)
|
|
216
|
+
- jxl (JPEG XL)
|
|
217
|
+
- png
|
|
218
|
+
- raw (headless raw data)
|
|
219
|
+
- tiff
|
|
220
|
+
- webp
|
|
221
|
+
|
|
222
|
+
### resize
|
|
223
|
+
|
|
224
|
+
Resizing image
|
|
225
|
+
|
|
226
|
+
- gravity or position
|
|
227
|
+
- fit modes
|
|
228
|
+
- supports px or percent units
|
|
229
|
+
- proportional to a given reference side/size
|
|
230
|
+
|
|
231
|
+
### rotate
|
|
232
|
+
|
|
233
|
+
Auto-rotate, rotate and/or mirror image
|
|
234
|
+
|
|
235
|
+
## Status
|
|
236
|
+
|
|
237
|
+
**ALPHA** - bleeding edge / work-in-progress
|
|
238
|
+
|
|
239
|
+
[Search or submit any issues for this package](https://github.com/thi-ng/umbrella/issues?q=%5Bimago%5D+in%3Atitle)
|
|
240
|
+
|
|
241
|
+
## Installation
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
yarn add @thi.ng/imago
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
For Node.js REPL:
|
|
248
|
+
|
|
249
|
+
```js
|
|
250
|
+
const imago = await import("@thi.ng/imago");
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 3.13 KB
|
|
254
|
+
|
|
255
|
+
## Dependencies
|
|
256
|
+
|
|
257
|
+
- [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
|
|
258
|
+
- [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
|
|
259
|
+
- [@thi.ng/date](https://github.com/thi-ng/umbrella/tree/develop/packages/date)
|
|
260
|
+
- [@thi.ng/defmulti](https://github.com/thi-ng/umbrella/tree/develop/packages/defmulti)
|
|
261
|
+
- [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)
|
|
262
|
+
- [@thi.ng/file-io](https://github.com/thi-ng/umbrella/tree/develop/packages/file-io)
|
|
263
|
+
- [@thi.ng/logger](https://github.com/thi-ng/umbrella/tree/develop/packages/logger)
|
|
264
|
+
- [@thi.ng/pixel](https://github.com/thi-ng/umbrella/tree/develop/packages/pixel)
|
|
265
|
+
- [@thi.ng/pixel-dither](https://github.com/thi-ng/umbrella/tree/develop/packages/pixel-dither)
|
|
266
|
+
- [sharp](https://sharp.pixelplumbing.com)
|
|
267
|
+
|
|
268
|
+
## API
|
|
269
|
+
|
|
270
|
+
[Generated API docs](https://docs.thi.ng/umbrella/imago/)
|
|
271
|
+
|
|
272
|
+
TODO
|
|
273
|
+
|
|
274
|
+
## Authors
|
|
275
|
+
|
|
276
|
+
- [Karsten Schmidt](https://thi.ng)
|
|
277
|
+
|
|
278
|
+
If this project contributes to an academic publication, please cite it as:
|
|
279
|
+
|
|
280
|
+
```bibtex
|
|
281
|
+
@misc{thing-imago,
|
|
282
|
+
title = "@thi.ng/imago",
|
|
283
|
+
author = "Karsten Schmidt",
|
|
284
|
+
note = "https://thi.ng/imago",
|
|
285
|
+
year = 2024
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## License
|
|
290
|
+
|
|
291
|
+
© 2024 Karsten Schmidt // Apache License 2.0
|
package/api.d.ts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type { Keys } from "@thi.ng/api";
|
|
2
|
+
import type { ILogger } from "@thi.ng/logger";
|
|
3
|
+
import type { AvifOptions, Blend, Exif, ExtendWith, FitEnum, GifOptions, Jp2Options, JpegOptions, JxlOptions, KernelEnum, Metadata, PngOptions, TiffOptions, TileOptions, WebpOptions } from "sharp";
|
|
4
|
+
export type Gravity = "c" | "e" | "n" | "ne" | "nw" | "s" | "se" | "sw" | "w";
|
|
5
|
+
export type DitherMode = "atkinson" | "burkes" | "column" | "diffusion" | "floyd" | "jarvis" | "row" | "sierra" | "stucki" | "bayer";
|
|
6
|
+
export type Dim = [number, number];
|
|
7
|
+
export type Size = number | Dim;
|
|
8
|
+
export type Sides = [number, number, number, number];
|
|
9
|
+
export type SizeRef = "min" | "max" | "w" | "h";
|
|
10
|
+
export type SizeUnit = "px" | "%";
|
|
11
|
+
export type Color = string | number[] | {
|
|
12
|
+
r: number;
|
|
13
|
+
g: number;
|
|
14
|
+
b: number;
|
|
15
|
+
alpha?: number;
|
|
16
|
+
};
|
|
17
|
+
export interface Position {
|
|
18
|
+
l?: number;
|
|
19
|
+
r?: number;
|
|
20
|
+
t?: number;
|
|
21
|
+
b?: number;
|
|
22
|
+
}
|
|
23
|
+
export interface ProcSpec {
|
|
24
|
+
type: string;
|
|
25
|
+
}
|
|
26
|
+
export interface BlurSpec extends ProcSpec {
|
|
27
|
+
type: "blur";
|
|
28
|
+
radius: number;
|
|
29
|
+
}
|
|
30
|
+
export interface CompSpec extends ProcSpec {
|
|
31
|
+
type: "composite";
|
|
32
|
+
layers: CompLayer[];
|
|
33
|
+
}
|
|
34
|
+
export type CompLayer = ImgLayer | SVGLayer;
|
|
35
|
+
export interface CompLayerBase {
|
|
36
|
+
type: string;
|
|
37
|
+
blend?: Blend;
|
|
38
|
+
gravity?: Gravity;
|
|
39
|
+
pos?: Position;
|
|
40
|
+
tile?: boolean;
|
|
41
|
+
unit?: SizeUnit;
|
|
42
|
+
}
|
|
43
|
+
export interface ImgLayer extends CompLayerBase {
|
|
44
|
+
path: string;
|
|
45
|
+
size?: Size;
|
|
46
|
+
unit?: SizeUnit;
|
|
47
|
+
}
|
|
48
|
+
export interface SVGLayer extends CompLayerBase {
|
|
49
|
+
type: "svg";
|
|
50
|
+
body: string;
|
|
51
|
+
path: string;
|
|
52
|
+
}
|
|
53
|
+
export interface CropSpec extends ProcSpec {
|
|
54
|
+
type: "crop";
|
|
55
|
+
border?: Size | Sides;
|
|
56
|
+
gravity?: Gravity;
|
|
57
|
+
pos?: Position;
|
|
58
|
+
ref?: SizeRef;
|
|
59
|
+
size?: Size;
|
|
60
|
+
unit?: SizeUnit;
|
|
61
|
+
}
|
|
62
|
+
export interface DitherSpec extends ProcSpec {
|
|
63
|
+
type: "dither";
|
|
64
|
+
mode: DitherMode;
|
|
65
|
+
num: number;
|
|
66
|
+
rgb?: boolean;
|
|
67
|
+
size: 2 | 4 | 8;
|
|
68
|
+
}
|
|
69
|
+
export interface EXIFSpec extends ProcSpec {
|
|
70
|
+
type: "exif";
|
|
71
|
+
tags: Exif;
|
|
72
|
+
}
|
|
73
|
+
export interface ExtendSpec extends ProcSpec {
|
|
74
|
+
type: "extend";
|
|
75
|
+
bg?: Color;
|
|
76
|
+
border: Size | Sides;
|
|
77
|
+
mode?: ExtendWith;
|
|
78
|
+
ref?: SizeRef;
|
|
79
|
+
unit?: SizeUnit;
|
|
80
|
+
}
|
|
81
|
+
export interface GammaSpec extends ProcSpec {
|
|
82
|
+
type: "gamma";
|
|
83
|
+
gamma: number;
|
|
84
|
+
}
|
|
85
|
+
export interface GrayscaleSpec extends ProcSpec {
|
|
86
|
+
type: "gray";
|
|
87
|
+
gamma?: number | boolean;
|
|
88
|
+
}
|
|
89
|
+
export interface HSBLSpec extends ProcSpec {
|
|
90
|
+
type: "hsbl";
|
|
91
|
+
h?: number;
|
|
92
|
+
s?: number;
|
|
93
|
+
b?: number;
|
|
94
|
+
l?: number;
|
|
95
|
+
}
|
|
96
|
+
export interface NestSpec extends ProcSpec {
|
|
97
|
+
type: "nest";
|
|
98
|
+
procs: ProcSpec[];
|
|
99
|
+
}
|
|
100
|
+
export interface OutputSpec extends ProcSpec {
|
|
101
|
+
type: "output";
|
|
102
|
+
path: string;
|
|
103
|
+
avif?: AvifOptions;
|
|
104
|
+
gif?: GifOptions;
|
|
105
|
+
jp2?: Jp2Options;
|
|
106
|
+
jpeg?: JpegOptions;
|
|
107
|
+
jxl?: JxlOptions;
|
|
108
|
+
png?: PngOptions;
|
|
109
|
+
raw?: boolean | {
|
|
110
|
+
/**
|
|
111
|
+
* If true, ensures the buffer has an alpha channel
|
|
112
|
+
*/
|
|
113
|
+
alpha?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* If true, writes a secondary file with this buffer's metadata (in
|
|
116
|
+
* the same dir, using `.meta.json` as suffix)
|
|
117
|
+
*/
|
|
118
|
+
meta?: boolean;
|
|
119
|
+
};
|
|
120
|
+
tile?: TileOptions;
|
|
121
|
+
tiff?: TiffOptions;
|
|
122
|
+
webp?: WebpOptions;
|
|
123
|
+
}
|
|
124
|
+
export interface ResizeSpec extends ProcSpec {
|
|
125
|
+
type: "resize";
|
|
126
|
+
bg?: Color;
|
|
127
|
+
filter?: Keys<KernelEnum>;
|
|
128
|
+
fit?: Keys<FitEnum>;
|
|
129
|
+
gravity?: Gravity;
|
|
130
|
+
size: Size;
|
|
131
|
+
unit?: SizeUnit;
|
|
132
|
+
}
|
|
133
|
+
export interface RotateSpec extends ProcSpec {
|
|
134
|
+
type: "rotate";
|
|
135
|
+
angle?: number;
|
|
136
|
+
bg: Color;
|
|
137
|
+
flipX?: boolean;
|
|
138
|
+
flipY?: boolean;
|
|
139
|
+
}
|
|
140
|
+
export interface ImgProcOpts {
|
|
141
|
+
/**
|
|
142
|
+
* Logger instance to use (by default uses builtin module logger, linked to
|
|
143
|
+
* umbrella `ROOT` logger)
|
|
144
|
+
*/
|
|
145
|
+
logger: ILogger;
|
|
146
|
+
/**
|
|
147
|
+
* Base directory for {@link output} steps
|
|
148
|
+
*/
|
|
149
|
+
outDir: string;
|
|
150
|
+
}
|
|
151
|
+
export interface ImgProcCtx {
|
|
152
|
+
path?: string;
|
|
153
|
+
size: Dim;
|
|
154
|
+
channels: 1 | 2 | 3 | 4;
|
|
155
|
+
meta: Metadata;
|
|
156
|
+
logger: ILogger;
|
|
157
|
+
opts: Partial<ImgProcOpts>;
|
|
158
|
+
}
|
|
159
|
+
export declare const GRAVITY_POSITION: Record<Gravity, string>;
|
|
160
|
+
export declare const GRAVITY_MAP: Record<Gravity, string>;
|
|
161
|
+
//# sourceMappingURL=api.d.ts.map
|
package/api.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const GRAVITY_POSITION = {
|
|
2
|
+
c: "center",
|
|
3
|
+
e: "right",
|
|
4
|
+
n: "top",
|
|
5
|
+
ne: "right top",
|
|
6
|
+
nw: "left top",
|
|
7
|
+
s: "bottom",
|
|
8
|
+
se: "right bottom",
|
|
9
|
+
sw: "left bottom",
|
|
10
|
+
w: "left"
|
|
11
|
+
};
|
|
12
|
+
const GRAVITY_MAP = {
|
|
13
|
+
n: "north",
|
|
14
|
+
ne: "northeast",
|
|
15
|
+
se: "southeast",
|
|
16
|
+
s: "south",
|
|
17
|
+
sw: "southwest",
|
|
18
|
+
w: "west",
|
|
19
|
+
nw: "northwest",
|
|
20
|
+
e: "east",
|
|
21
|
+
c: "center"
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
GRAVITY_MAP,
|
|
25
|
+
GRAVITY_POSITION
|
|
26
|
+
};
|