imagescript 1.3.1 → 3.0.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/LICENSE +4 -1
- package/README.md +64 -26
- package/THIRD_PARTY_NOTICES.md +74 -0
- package/dist/codecs/crc.d.ts +9 -0
- package/dist/codecs/crc.js +29 -0
- package/dist/codecs/exif.d.ts +11 -0
- package/dist/codecs/exif.js +27 -0
- package/dist/codecs/gif.d.ts +44 -0
- package/dist/codecs/gif.js +401 -0
- package/dist/codecs/jpeg.d.ts +35 -0
- package/dist/codecs/jpeg.js +980 -0
- package/dist/codecs/png.d.ts +44 -0
- package/dist/codecs/png.js +442 -0
- package/dist/codecs/quantize.d.ts +25 -0
- package/dist/codecs/quantize.js +302 -0
- package/dist/codecs/tiff.d.ts +6 -0
- package/dist/codecs/tiff.js +546 -0
- package/dist/codecs/zlib.d.ts +22 -0
- package/dist/codecs/zlib.js +607 -0
- package/dist/frame.d.ts +57 -0
- package/dist/frame.js +65 -0
- package/dist/gif.d.ts +44 -0
- package/dist/gif.js +93 -0
- package/dist/image-type.d.ts +20 -0
- package/dist/image-type.js +49 -0
- package/dist/image.d.ts +521 -0
- package/dist/image.js +1118 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +13 -0
- package/dist/package.json +1 -0
- package/dist/render/font.d.ts +63 -0
- package/dist/render/font.js +857 -0
- package/dist/render/svg.d.ts +11 -0
- package/dist/render/svg.js +1717 -0
- package/dist/render/text.d.ts +61 -0
- package/dist/render/text.js +317 -0
- package/dist/text-layout.d.ts +46 -0
- package/dist/text-layout.js +35 -0
- package/dist/util/blur.d.ts +13 -0
- package/dist/util/blur.js +146 -0
- package/dist/util/mem.d.ts +10 -0
- package/dist/util/mem.js +23 -0
- package/dist/util/resample.d.ts +12 -0
- package/dist/util/resample.js +99 -0
- package/dist/util/utf8.d.ts +5 -0
- package/dist/util/utf8.js +55 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/licenses/Apache-2.0.txt +202 -0
- package/licenses/README.ijg +260 -0
- package/package.json +31 -7
- package/ImageScript.d.ts +0 -954
- package/ImageScript.js +0 -1669
- package/bench/_.mjs +0 -166
- package/bench/all.mjs +0 -4
- package/bench/blur.mjs +0 -59
- package/bench/flip.mjs +0 -63
- package/bench/overlay.mjs +0 -35
- package/bench/package.json +0 -7
- package/bench/readme.md +0 -64
- package/bench/resize.mjs +0 -52
- package/codecs/LICENSE +0 -21
- package/codecs/lib.d.ts +0 -50
- package/codecs/lib.js +0 -6
- package/codecs/lib.mjs +0 -1
- package/codecs/node/bin/arm64-darwin.node +0 -0
- package/codecs/node/bin/arm64-linux.node +0 -0
- package/codecs/node/bin/x64-darwin.node +0 -0
- package/codecs/node/bin/x64-linux.node +0 -0
- package/codecs/node/bin/x64-win32.node +0 -0
- package/codecs/node/index.js +0 -3
- package/codecs/node/index.mjs +0 -6
- package/codecs/package.json +0 -14
- package/codecs/readme.md +0 -38
- package/codecs/wasm/bin/codecs.wasm +0 -0
- package/codecs/wasm/bin/simd.wasm +0 -0
- package/codecs/wasm/bundle/browser.js +0 -1
- package/codecs/wasm/index.js +0 -1
- package/codecs/wasm/index.mjs +0 -1
- package/png/README.md +0 -1
- package/png/node.js +0 -1137
- package/png/src/crc.mjs +0 -49
- package/png/src/mem.mjs +0 -24
- package/png/src/png.mjs +0 -254
- package/png/src/zlib.mjs +0 -618
- package/tsconfig.json +0 -21
- package/utils/mem.js +0 -26
- package/v2/codecs/magic.js +0 -25
- package/v2/framebuffer.d.ts +0 -67
- package/v2/framebuffer.js +0 -2352
- package/v2/framebuffer.mjs +0 -126
- package/v2/framebuffer.rs +0 -1264
- package/v2/index.d.ts +0 -84
- package/v2/index.js +0 -261
- package/v2/ops/blur.mjs +0 -303
- package/v2/ops/color.mjs +0 -277
- package/v2/ops/crop.mjs +0 -64
- package/v2/ops/fill.mjs +0 -33
- package/v2/ops/flip.mjs +0 -33
- package/v2/ops/index.mjs +0 -9
- package/v2/ops/iterator.mjs +0 -34
- package/v2/ops/overlay.mjs +0 -63
- package/v2/ops/resize.mjs +0 -166
- package/v2/ops/rotate.mjs +0 -117
- package/v2/util/mem.mjs +0 -24
- package/wasm/any/font.wasm +0 -0
- package/wasm/any/gif.wasm +0 -0
- package/wasm/any/jpeg.wasm +0 -0
- package/wasm/any/png.wasm +0 -0
- package/wasm/any/svg.wasm +0 -0
- package/wasm/any/tiff.wasm +0 -0
- package/wasm/node/font.js +0 -142
- package/wasm/node/gif.js +0 -76
- package/wasm/node/jpeg.js +0 -92
- package/wasm/node/png.js +0 -49
- package/wasm/node/svg.js +0 -56
- package/wasm/node/tiff.js +0 -47
package/LICENSE
CHANGED
|
@@ -9,4 +9,7 @@ mentioned licenses, but a license must be chosen.
|
|
|
9
9
|
|
|
10
10
|
The corresponding license files can be found in the projects
|
|
11
11
|
root directory, prefixed with LICENSE, suffixed with their
|
|
12
|
-
corresponding SPDX identifier.
|
|
12
|
+
corresponding SPDX identifier.
|
|
13
|
+
|
|
14
|
+
Parts of this software are derived from third party projects under their
|
|
15
|
+
own licenses (MIT, Apache-2.0 and the IJG license), see THIRD_PARTY_NOTICES.md.
|
package/README.md
CHANGED
|
@@ -3,49 +3,87 @@
|
|
|
3
3
|
[](https://discord.gg/8hPrwAH)
|
|
4
4
|
[](https://imagescript.matmen.dev/)
|
|
5
5
|
[](https://github.com/matmen/ImageScript)
|
|
6
|
-
[](https://deno.land/x/imagescript)
|
|
7
6
|
[](https://www.npmjs.com/package/imagescript)
|
|
8
7
|
|
|
9
8
|
---
|
|
10
9
|
|
|
11
|
-
**ImageScript** is a zero-dependency alternative to common JavaScript bitmap image manipulation tools.
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
**ImageScript** is a zero-dependency alternative to common JavaScript bitmap image manipulation tools. Every codec and
|
|
11
|
+
renderer is written in TypeScript: no WebAssembly, no native binaries, no npm dependencies, no install scripts. The
|
|
12
|
+
package is about 120 kB (compressed) and runs in Node.js 22.13 or newer (including Alpine/musl, ARM and bundled
|
|
13
|
+
serverless functions), Deno, Bun and browsers. It works with both `import` and `require()`, type definitions are included.
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install imagescript # Node.js, Bun and bundlers
|
|
17
|
+
deno add jsr:@matmen/imagescript # Deno (npm:imagescript works too)
|
|
18
|
+
```
|
|
14
19
|
|
|
15
20
|
---
|
|
16
21
|
|
|
17
22
|
### Features
|
|
18
23
|
|
|
19
|
-
- [Decoding images](https://imagescript.matmen.dev/Image.html
|
|
20
|
-
- PNGs (grayscale, RGB, indexed colors) with and without alpha channels
|
|
21
|
-
- JPEGs (grayscale, RGB, CMYK)
|
|
22
|
-
- TIFFs
|
|
23
|
-
-
|
|
24
|
-
- [
|
|
25
|
-
- [Rendering
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
-
|
|
30
|
-
, [
|
|
31
|
-
|
|
32
|
-
, [
|
|
33
|
-
-
|
|
34
|
-
, [
|
|
35
|
-
, [
|
|
36
|
-
|
|
24
|
+
- [Decoding images](https://imagescript.matmen.dev/classes/Image.html#decode)
|
|
25
|
+
- PNGs (grayscale, RGB, indexed colors, 1-16 bit, interlaced) with and without alpha channels
|
|
26
|
+
- JPEGs (baseline and progressive; grayscale, RGB, CMYK)
|
|
27
|
+
- TIFFs (strips and tiles; uncompressed, LZW, deflate, PackBits and JPEG compressed; BigTIFF)
|
|
28
|
+
- JPEGs, TIFFs and PNGs are rotated as their Exif (or, for PNGs, XMP) orientation says
|
|
29
|
+
- [Decoding GIFs](https://imagescript.matmen.dev/classes/GIF.html#decode) with all frames, durations and disposal modes
|
|
30
|
+
- [Rendering SVGs](https://imagescript.matmen.dev/classes/Image.html#rendersvg) (shapes, paths, gradients, strokes, clip paths,
|
|
31
|
+
masks, CSS; no text, images or filters)
|
|
32
|
+
- [Rendering vector fonts](https://imagescript.matmen.dev/classes/Image.html#rendertext) (TrueType and OpenType, with kerning and outlines)
|
|
33
|
+
- [Resizing](https://imagescript.matmen.dev/classes/Image.html#resize) (bilinear, bicubic, area averaging and nearest neighbor)
|
|
34
|
+
- Image manipulation functions ([crop](https://imagescript.matmen.dev/classes/Image.html#crop)
|
|
35
|
+
, [rotate](https://imagescript.matmen.dev/classes/Image.html#rotate)
|
|
36
|
+
, [cropCircle](https://imagescript.matmen.dev/classes/Image.html#cropcircle)
|
|
37
|
+
, [roundCorners](https://imagescript.matmen.dev/classes/Image.html#roundcorners), ...)
|
|
38
|
+
- Filters and color adjustments ([blur](https://imagescript.matmen.dev/classes/Image.html#blur)
|
|
39
|
+
, [sharpen](https://imagescript.matmen.dev/classes/Image.html#sharpen)
|
|
40
|
+
, [brightness](https://imagescript.matmen.dev/classes/Image.html#brightness)
|
|
41
|
+
, [hueShift](https://imagescript.matmen.dev/classes/Image.html#hueshift), ...)
|
|
42
|
+
- Compositing with opacity and blend modes ([composite](https://imagescript.matmen.dev/classes/Image.html#composite))
|
|
43
|
+
- Color information functions ([averageColor](https://imagescript.matmen.dev/classes/Image.html#averagecolor)
|
|
44
|
+
, [dominantColor](https://imagescript.matmen.dev/classes/Image.html#dominantcolor), ...)
|
|
45
|
+
- Encoding images as [PNGs](https://imagescript.matmen.dev/classes/Image.html#encode) (smallest lossless color type)
|
|
46
|
+
, [JPEGs](https://imagescript.matmen.dev/classes/Image.html#encodejpeg)
|
|
47
|
+
and animated [GIFs](https://imagescript.matmen.dev/classes/GIF.html#encode)
|
|
37
48
|
|
|
38
49
|
---
|
|
39
50
|
|
|
40
51
|
### Example
|
|
41
52
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
```js
|
|
54
|
+
import { Image } from 'imagescript';
|
|
55
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
56
|
+
|
|
57
|
+
const image = await Image.decode(await readFile('input.jpg'));
|
|
58
|
+
image.resize(256, Image.RESIZE_AUTO).roundCorners(16);
|
|
59
|
+
await writeFile('output.png', await image.encode());
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
With CommonJS:
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
const { Image } = require('imagescript');
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
All coordinates are 0-based, `(0, 0)` is the top left pixel.
|
|
69
|
+
|
|
70
|
+
A bigger example is the [README image generation](https://github.com/matmen/ImageScript/blob/master/tests/readme.js).
|
|
71
|
+
Upgrading from 1.x? Version 3 has breaking changes (0-based coordinates, removed WebP encoding, Node.js 22.13+, ...),
|
|
72
|
+
see the [changelog](https://github.com/matmen/ImageScript/blob/master/CHANGELOG.md). There is no 2.x release, the number was skipped because of the old experimental
|
|
73
|
+
`imagescript/v2` API.
|
|
46
74
|
|
|
47
75
|
[](https://github.com/matmen/ImageScript/blob/master/tests/readme.js)
|
|
48
76
|
|
|
49
77
|
---
|
|
50
78
|
|
|
79
|
+
### Credits
|
|
80
|
+
|
|
81
|
+
The deflate/inflate implementation is derived from [fflate](https://github.com/101arrowz/fflate) and the CRC-32 from
|
|
82
|
+
[Fast CRC32 in JavaScript](https://gist.github.com/101arrowz/e58695f7ccfdf74f60ba22018093edea), both by Arjun Barrett.
|
|
83
|
+
The JPEG codec is based in part on the work of the Independent JPEG Group (libjpeg) and on
|
|
84
|
+
[pdf.js](https://github.com/mozilla/pdf.js), the glyph rasterizer is translated from
|
|
85
|
+
[font-rs](https://github.com/raphlinus/font-rs). See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) for their licenses.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
51
89
|
If you have any additional questions, feel free to join the [discord support server](https://discord.gg/8hPrwAH).
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Third party notices
|
|
2
|
+
|
|
3
|
+
ImageScript is licensed under AGPL-3.0-or-later OR MIT (see [LICENSE](LICENSE)). Parts of it are derived from the
|
|
4
|
+
following projects, under their own licenses. Each derived file says so in its header.
|
|
5
|
+
|
|
6
|
+
| Project | Used in | License |
|
|
7
|
+
|---|---|---|
|
|
8
|
+
| [fflate](https://github.com/101arrowz/fflate) by Arjun Barrett | `src/codecs/zlib.ts` (deflate/inflate) | MIT |
|
|
9
|
+
| [Fast CRC32 in JavaScript](https://gist.github.com/101arrowz/e58695f7ccfdf74f60ba22018093edea) by Arjun Barrett | `src/codecs/crc.ts` (slice-by-16 CRC-32) | MIT |
|
|
10
|
+
| [libjpeg](https://ijg.org/) / [libjpeg-turbo](https://libjpeg-turbo.org/) by the Independent JPEG Group | `src/codecs/jpeg.ts` (IDCT, FDCT, upsampling, color conversion, progressive refinement, optimal Huffman tables) | IJG |
|
|
11
|
+
| [pdf.js](https://github.com/mozilla/pdf.js) (forked from [jpgjs](https://github.com/notmasteryet/jpgjs) by notmasteryet) | `src/codecs/jpeg.ts` (structure of the scan decoder) | Apache-2.0 |
|
|
12
|
+
| [font-rs](https://github.com/raphlinus/font-rs) by Raph Levien | `src/render/text.ts` (the `Rasterizer` class, also used for SVGs) | Apache-2.0 |
|
|
13
|
+
|
|
14
|
+
## fflate, Fast CRC32 in JavaScript
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
MIT License
|
|
18
|
+
|
|
19
|
+
Copyright (c) 2020 Arjun Barrett (fflate)
|
|
20
|
+
Copyright (c) 2021 Arjun Barrett (Fast CRC32 in JavaScript)
|
|
21
|
+
|
|
22
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
23
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
24
|
+
in the Software without restriction, including without limitation the rights
|
|
25
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
26
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
27
|
+
furnished to do so, subject to the following conditions:
|
|
28
|
+
|
|
29
|
+
The above copyright notice and this permission notice shall be included in all
|
|
30
|
+
copies or substantial portions of the Software.
|
|
31
|
+
|
|
32
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
33
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
34
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
35
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
36
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
37
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
38
|
+
SOFTWARE.
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## libjpeg / libjpeg-turbo
|
|
42
|
+
|
|
43
|
+
This software is based in part on the work of the Independent JPEG Group.
|
|
44
|
+
|
|
45
|
+
The JPEG codec translates parts of libjpeg (as shipped by libjpeg-turbo) to TypeScript: the integer inverse DCT
|
|
46
|
+
(`jidctint.c`), the floating point forward DCT (`jfdctflt.c`), fancy upsampling (`jdsample.c`), the YCbCr to RGB
|
|
47
|
+
tables (`jdcolor.c`), the progressive AC refinement (`jdphuff.c`) and the optimal Huffman table generation
|
|
48
|
+
(`jcphuff.c`/`jchuff.c`). The translations were rewritten for TypeScript's numbers and typed arrays; the rest of the
|
|
49
|
+
codec is ImageScript's own. libjpeg's README with its copyright and terms is included unaltered as
|
|
50
|
+
[licenses/README.ijg](licenses/README.ijg).
|
|
51
|
+
|
|
52
|
+
## pdf.js, font-rs
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
pdf.js: Copyright 2014 Mozilla Foundation
|
|
56
|
+
font-rs: Copyright 2015 Google Inc. All rights reserved.
|
|
57
|
+
|
|
58
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
59
|
+
you may not use this file except in compliance with the License.
|
|
60
|
+
You may obtain a copy of the License at
|
|
61
|
+
|
|
62
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
63
|
+
|
|
64
|
+
Unless required by applicable law or agreed to in writing, software
|
|
65
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
66
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
67
|
+
See the License for the specific language governing permissions and
|
|
68
|
+
limitations under the License.
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The scan decoder of `src/codecs/jpeg.ts` follows the structure of pdf.js' `src/core/jpg.js` (block and MCU layout,
|
|
72
|
+
one decode function per scan type). The `Rasterizer` class in `src/render/text.ts` is a translation of font-rs'
|
|
73
|
+
`Raster` from Rust to TypeScript (`draw_line`, `draw_quad`, `accumulate`); its `cubic` method is adapted from
|
|
74
|
+
`draw_quad`. The full license text is in [licenses/Apache-2.0.txt](licenses/Apache-2.0.txt).
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Slice-by-16 CRC-32, derived from "Fast CRC32 in JavaScript" (https://gist.github.com/101arrowz/e58695f7ccfdf74f60ba22018093edea)
|
|
3
|
+
* Copyright (c) 2021 Arjun Barrett, MIT License (see THIRD_PARTY_NOTICES.md)
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* CRC-32 (ISO 3309), as used by PNG and zlib. Processes 16 bytes per step (slice-by-16, see #12), byte by byte so
|
|
7
|
+
* it doesn't depend on alignment or endianness
|
|
8
|
+
*/
|
|
9
|
+
export declare function crc32(buffer: Uint8Array): number;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Slice-by-16 CRC-32, derived from "Fast CRC32 in JavaScript" (https://gist.github.com/101arrowz/e58695f7ccfdf74f60ba22018093edea)
|
|
3
|
+
* Copyright (c) 2021 Arjun Barrett, MIT License (see THIRD_PARTY_NOTICES.md)
|
|
4
|
+
*/
|
|
5
|
+
const TABLE = new Int32Array(16 * 256);
|
|
6
|
+
for (let n = 0; n < 256; n++) {
|
|
7
|
+
let c = n;
|
|
8
|
+
for (let k = 0; k < 8; k++)
|
|
9
|
+
c = c & 1 ? 0xedb88320 ^ c >>> 1 : c >>> 1;
|
|
10
|
+
TABLE[n] = c;
|
|
11
|
+
}
|
|
12
|
+
for (let n = 0; n < 256; n++) {
|
|
13
|
+
let c = TABLE[n];
|
|
14
|
+
for (let k = 256; k < TABLE.length; k += 256)
|
|
15
|
+
c = TABLE[k + n] = TABLE[c & 0xff] ^ c >>> 8;
|
|
16
|
+
}
|
|
17
|
+
export function crc32(buffer) {
|
|
18
|
+
let crc = -1, i = 0;
|
|
19
|
+
for (const end = buffer.length - 16; i <= end; i += 16) {
|
|
20
|
+
crc = TABLE[3840 + ((buffer[i] ^ crc) & 0xff)] ^ TABLE[3584 + ((buffer[i + 1] ^ crc >> 8) & 0xff)]
|
|
21
|
+
^ TABLE[3328 + ((buffer[i + 2] ^ crc >> 16) & 0xff)] ^ TABLE[3072 + (buffer[i + 3] ^ crc >>> 24)]
|
|
22
|
+
^ TABLE[2816 + buffer[i + 4]] ^ TABLE[2560 + buffer[i + 5]] ^ TABLE[2304 + buffer[i + 6]] ^ TABLE[2048 + buffer[i + 7]]
|
|
23
|
+
^ TABLE[1792 + buffer[i + 8]] ^ TABLE[1536 + buffer[i + 9]] ^ TABLE[1280 + buffer[i + 10]] ^ TABLE[1024 + buffer[i + 11]]
|
|
24
|
+
^ TABLE[768 + buffer[i + 12]] ^ TABLE[512 + buffer[i + 13]] ^ TABLE[256 + buffer[i + 14]] ^ TABLE[buffer[i + 15]];
|
|
25
|
+
}
|
|
26
|
+
for (; i < buffer.length; i++)
|
|
27
|
+
crc = TABLE[(crc ^ buffer[i]) & 0xff] ^ crc >>> 8;
|
|
28
|
+
return (crc ^ -1) >>> 0;
|
|
29
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the orientation tag (0x0112) from the first IFD of Exif data
|
|
3
|
+
* @param data a TIFF header and IFDs, optionally preceded by "Exif\0\0" (as in JPEG's APP1)
|
|
4
|
+
* @return the orientation (1-8), 1 if it is missing or invalid
|
|
5
|
+
*/
|
|
6
|
+
export declare function orientation(data: Uint8Array): number;
|
|
7
|
+
/**
|
|
8
|
+
* Reads tiff:Orientation from an XMP packet, as attribute or element
|
|
9
|
+
* @return the orientation (1-8), 1 if it is missing or invalid
|
|
10
|
+
*/
|
|
11
|
+
export declare function xmpOrientation(xmp: string): number;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function orientation(data) {
|
|
2
|
+
if (data.length >= 6 && data[0] === 0x45 && data[1] === 0x78 && data[2] === 0x69 && data[3] === 0x66 && data[4] === 0 && data[5] === 0)
|
|
3
|
+
data = data.subarray(6);
|
|
4
|
+
if (data.length < 8)
|
|
5
|
+
return 1;
|
|
6
|
+
const tiff = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
7
|
+
const little = tiff.getUint16(0) === 0x4949;
|
|
8
|
+
if (!little && tiff.getUint16(0) !== 0x4d4d)
|
|
9
|
+
return 1;
|
|
10
|
+
const ifd = tiff.getUint32(4, little);
|
|
11
|
+
if (ifd + 2 > tiff.byteLength)
|
|
12
|
+
return 1;
|
|
13
|
+
for (let i = 0, count = tiff.getUint16(ifd, little); i < count; i++) {
|
|
14
|
+
const entry = ifd + 2 + i * 12;
|
|
15
|
+
if (entry + 12 > tiff.byteLength)
|
|
16
|
+
break;
|
|
17
|
+
if (tiff.getUint16(entry, little) !== 0x0112)
|
|
18
|
+
continue;
|
|
19
|
+
const value = tiff.getUint16(entry + 8, little);
|
|
20
|
+
return value >= 1 && value <= 8 ? value : 1;
|
|
21
|
+
}
|
|
22
|
+
return 1;
|
|
23
|
+
}
|
|
24
|
+
export function xmpOrientation(xmp) {
|
|
25
|
+
const match = /tiff:Orientation\s*(?:=\s*["']|>\s*)([1-8])\b/.exec(xmp);
|
|
26
|
+
return match ? +match[1] : 1;
|
|
27
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface GIFFrame {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
/** Frame delay in centiseconds */
|
|
7
|
+
delay: number;
|
|
8
|
+
/** ImageScript disposal mode (0 any, 1 keep, 2 previous, 3 background) */
|
|
9
|
+
dispose: number;
|
|
10
|
+
/** RGBA pixel data */
|
|
11
|
+
pixels: Uint8Array;
|
|
12
|
+
}
|
|
13
|
+
export interface GIFData {
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
/** -1 loops forever, 0 plays once, n repeats n times */
|
|
17
|
+
loopCount: number;
|
|
18
|
+
frames: GIFFrame[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Encodes frames into a GIF
|
|
22
|
+
* @param {{width: number, height: number, loopCount?: number, frames: GIFFrame[]}} gif loopCount -1 loops forever, 0 plays once, n repeats n times
|
|
23
|
+
* @param {number} [quality=95] 1-100, scales the palette size (1 = 8 colors, 50 = 55, 90 and above = 256)
|
|
24
|
+
* @return {Uint8Array}
|
|
25
|
+
*/
|
|
26
|
+
export declare function encode({ width, height, loopCount, frames }: Omit<GIFData, 'loopCount'> & {
|
|
27
|
+
loopCount?: number;
|
|
28
|
+
}, quality?: number): Uint8Array;
|
|
29
|
+
/**
|
|
30
|
+
* Decodes a GIF into its individual (uncomposited) frames, zero-sized images are skipped
|
|
31
|
+
* @param {Uint8Array} data
|
|
32
|
+
* @param {boolean} [onlyFirstFrame=false]
|
|
33
|
+
* @return {{width: number, height: number, loopCount: number, frames: GIFFrame[]}}
|
|
34
|
+
*/
|
|
35
|
+
export declare function decode(data: Uint8Array, onlyFirstFrame?: boolean): GIFData;
|
|
36
|
+
/**
|
|
37
|
+
* Composites decoded frames onto the logical screen, applying their disposal modes
|
|
38
|
+
* @param {{width: number, height: number, frames: GIFFrame[]}} gif output of {@link decode}
|
|
39
|
+
* @return {Array<{pixels: Uint8Array, delay: number}>} full screen RGBA frames
|
|
40
|
+
*/
|
|
41
|
+
export declare function composite({ width, height, frames }: GIFData): Array<{
|
|
42
|
+
pixels: Uint8Array;
|
|
43
|
+
delay: number;
|
|
44
|
+
}>;
|