@tonpc64/vixel-wasm 0.2.0 → 0.3.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 +3 -0
- package/README.md +20 -4
- package/package.json +1 -1
- package/vixel.d.ts +8 -2
- package/vixel.js +29 -0
- package/vixel_bg.wasm +0 -0
- package/vixel_bg.wasm.d.ts +3 -2
package/LICENSE
CHANGED
|
@@ -2,6 +2,9 @@ MIT License
|
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2026 Chanwit Piromplad
|
|
4
4
|
|
|
5
|
+
Bundled Heifer components (heifer, heifer-hevc-dec, and heifer-isobmff) are
|
|
6
|
+
Copyright (c) 2026 heifer contributors and distributed under these MIT terms.
|
|
7
|
+
|
|
5
8
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
9
|
of this software and associated documentation files (the "Software"), to deal
|
|
7
10
|
in the Software without restriction, including without limitation the rights
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Use Vixel's WebAssembly module to resize and convert local images in a modern br
|
|
|
4
4
|
|
|
5
5
|
## Install with npm
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Add the published package to your frontend project.
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
10
|
npm install @tonpc64/vixel-wasm
|
|
@@ -19,6 +19,8 @@ await init();
|
|
|
19
19
|
const output = resize(input, 800, 600, "webp");
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
The Vite example builds Vixel from source and runs it in a Web Worker. It previews the original and resized images, supports iPhone HEIC and HEIF files, and loads a separate encoder for lossy WebP. [Live demo](https://tonpc64.github.io/vixel/) · [Run the example locally](https://github.com/TonPC64/vixel/tree/main/examples/wasm-web/)
|
|
23
|
+
|
|
22
24
|
## Get the browser bundle
|
|
23
25
|
|
|
24
26
|
Download and extract `vixel-web.tar.gz`. The `vixel-web/` directory contains the JavaScript module, the `.wasm` binary, and TypeScript declarations. [Download the browser bundle](https://github.com/TonPC64/vixel/releases/latest/download/vixel-web.tar.gz)
|
|
@@ -106,14 +108,28 @@ After calling `await init()` once, pass a `Uint8Array` to `resize(input, maxWidt
|
|
|
106
108
|
|
|
107
109
|
The module reads JPEG, PNG, WebP, GIF, TIFF, BMP, and ICO. It writes JPEG, PNG, lossless WebP, GIF, and TIFF. Animated inputs produce a still image. Input limits are 32 MiB, 24 megapixels, and 8192 pixels per side. Run `resize` in a Web Worker to keep the page responsive while processing large files.
|
|
108
110
|
|
|
109
|
-
|
|
111
|
+
Version 0.3.0 and newer also accept HEIC and HEIF still-photo bytes directly. Read the selected file with `new Uint8Array(await file.arrayBuffer())` and pass it to `resize` as shown above. For larger images such as 48-megapixel iPhone photos, use the CLI, the server, or the live demo's fallback decoder.
|
|
112
|
+
|
|
113
|
+
## Read source dimensions
|
|
114
|
+
|
|
115
|
+
Version 0.3.0 and newer export `image_dimensions(input)`. It reads the header and returns a `Uint32Array` containing the displayed width and height, including image orientation. It accepts the same input formats and 32 MiB file limit as `resize` and can inspect larger resolutions because it does not decode pixels.
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
import init, { image_dimensions } from "./vixel-web/vixel.js";
|
|
119
|
+
|
|
120
|
+
await init();
|
|
121
|
+
const input = new Uint8Array(await file.arrayBuffer());
|
|
122
|
+
const [width, height] = image_dimensions(input);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
For additional source metadata, use `vixel img info` or call the server's `/info` endpoint. [CLI metadata](https://github.com/TonPC64/vixel/blob/main/docs/cli.md#inspect-an-image) · [Server metadata](https://github.com/TonPC64/vixel/blob/main/docs/server.md#inspect-image-metadata)
|
|
110
126
|
|
|
111
127
|
## Publish the npm package
|
|
112
128
|
|
|
113
|
-
For the first version, run `make wasm-npm` with the build tools listed above. The command prints the npm tarball filename and uses the Cargo package version. Sign in with `npm login` and publish the tarball. For version `0.
|
|
129
|
+
For the first version, run `make wasm-npm` with the build tools listed above. The command prints the npm tarball filename and uses the Cargo package version. Sign in with `npm login` and publish the tarball. For version `0.3.0`, run the following command.
|
|
114
130
|
|
|
115
131
|
```sh
|
|
116
|
-
npm publish ./target/tonpc64-vixel-wasm-0.
|
|
132
|
+
npm publish ./target/tonpc64-vixel-wasm-0.3.0.tgz --access public
|
|
117
133
|
```
|
|
118
134
|
|
|
119
135
|
In the npm package settings, add a GitHub Actions trusted publisher for owner `TonPC64`, repository `vixel`, and workflow `release.yml`. Allow `npm publish` and leave the environment field empty. Subsequent GitHub releases publish the matching version to npm. [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/)
|
package/package.json
CHANGED
package/vixel.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Reads displayed source width and height without decoding the pixels.
|
|
6
|
+
*/
|
|
7
|
+
export function image_dimensions(input: Uint8Array): Uint32Array;
|
|
8
|
+
|
|
4
9
|
/**
|
|
5
10
|
* Fits an image inside a bounding box without enlargement and encodes it into the requested format.
|
|
6
11
|
*/
|
|
@@ -10,12 +15,13 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
10
15
|
|
|
11
16
|
export interface InitOutput {
|
|
12
17
|
readonly memory: WebAssembly.Memory;
|
|
18
|
+
readonly image_dimensions: (a: any) => [number, number, number, number];
|
|
13
19
|
readonly resize: (a: any, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
|
|
14
20
|
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
21
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
22
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
15
23
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
16
24
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
17
|
-
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
18
|
-
readonly __externref_table_dealloc: (a: number) => void;
|
|
19
25
|
readonly __wbindgen_start: () => void;
|
|
20
26
|
}
|
|
21
27
|
|
package/vixel.js
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
/* @ts-self-types="./vixel.d.ts" */
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Reads displayed source width and height without decoding the pixels.
|
|
5
|
+
* @param {Uint8Array} input
|
|
6
|
+
* @returns {Uint32Array}
|
|
7
|
+
*/
|
|
8
|
+
export function image_dimensions(input) {
|
|
9
|
+
const ret = wasm.image_dimensions(input);
|
|
10
|
+
if (ret[3]) {
|
|
11
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
12
|
+
}
|
|
13
|
+
var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
|
|
14
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
15
|
+
return v1;
|
|
16
|
+
}
|
|
17
|
+
|
|
3
18
|
/**
|
|
4
19
|
* Fits an image inside a bounding box without enlargement and encodes it into the requested format.
|
|
5
20
|
* @param {Uint8Array} input
|
|
@@ -55,6 +70,11 @@ function __wbg_get_imports() {
|
|
|
55
70
|
};
|
|
56
71
|
}
|
|
57
72
|
|
|
73
|
+
function getArrayU32FromWasm0(ptr, len) {
|
|
74
|
+
ptr = ptr >>> 0;
|
|
75
|
+
return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
76
|
+
}
|
|
77
|
+
|
|
58
78
|
function getArrayU8FromWasm0(ptr, len) {
|
|
59
79
|
ptr = ptr >>> 0;
|
|
60
80
|
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
@@ -65,6 +85,14 @@ function getStringFromWasm0(ptr, len) {
|
|
|
65
85
|
return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
66
86
|
}
|
|
67
87
|
|
|
88
|
+
let cachedUint32ArrayMemory0 = null;
|
|
89
|
+
function getUint32ArrayMemory0() {
|
|
90
|
+
if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
|
|
91
|
+
cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
|
|
92
|
+
}
|
|
93
|
+
return cachedUint32ArrayMemory0;
|
|
94
|
+
}
|
|
95
|
+
|
|
68
96
|
let cachedUint8ArrayMemory0 = null;
|
|
69
97
|
function getUint8ArrayMemory0() {
|
|
70
98
|
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
@@ -154,6 +182,7 @@ function __wbg_finalize_init(instance, module) {
|
|
|
154
182
|
wasmInstance = instance;
|
|
155
183
|
wasm = instance.exports;
|
|
156
184
|
wasmModule = module;
|
|
185
|
+
cachedUint32ArrayMemory0 = null;
|
|
157
186
|
cachedUint8ArrayMemory0 = null;
|
|
158
187
|
wasm.__wbindgen_start();
|
|
159
188
|
return wasm;
|
package/vixel_bg.wasm
CHANGED
|
Binary file
|
package/vixel_bg.wasm.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const image_dimensions: (a: any) => [number, number, number, number];
|
|
4
5
|
export const resize: (a: any, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
|
|
5
6
|
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
7
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
8
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
6
9
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
7
10
|
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
8
|
-
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
9
|
-
export const __externref_table_dealloc: (a: number) => void;
|
|
10
11
|
export const __wbindgen_start: () => void;
|