wasm-image-processor 0.2.0 → 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/README.md +26 -45
- package/package.json +1 -1
- package/wasm_image_processor_bg.js +25 -0
- package/wasm_image_processor_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ A high-performance image processing toolkit built with Rust and WebAssembly. Pro
|
|
|
16
16
|
|
|
17
17
|
## Demo
|
|
18
18
|
|
|
19
|
-
Try the live demo at: [https://
|
|
19
|
+
Try the live demo at: [https://wasm-ip-demo.vercel.app](https://wasm-ip-demo.vercel.app)
|
|
20
20
|
|
|
21
21
|
- **Basic Resizer**: Resize images to custom dimensions
|
|
22
22
|
- **PWA Icon Generator**: Generate complete icon sets for web apps
|
|
@@ -34,57 +34,38 @@ Try the live demo at: [https://stanleymasinde.github.io/wasm-image-processor/](h
|
|
|
34
34
|
npm i wasm-image-processor
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
### Prerequisites
|
|
40
|
-
|
|
41
|
-
- [Rust](https://rustup.rs/)
|
|
42
|
-
- [wasm-pack](https://rustwasm.github.io/wasm-pack/)
|
|
43
|
-
|
|
44
|
-
### Steps
|
|
45
|
-
1. Clone the repository:
|
|
46
|
-
```bash
|
|
47
|
-
git clone https://github.com/yourusername/wasm-image-processor.git
|
|
48
|
-
cd wasm-image-processor
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
2. Build the WASM package:
|
|
52
|
-
```bash
|
|
53
|
-
wasm-pack build --target web
|
|
54
|
-
```
|
|
37
|
+
### Usage
|
|
55
38
|
|
|
56
|
-
|
|
57
|
-
```bash
|
|
58
|
-
# Copy JS and WASM files to demo folder
|
|
59
|
-
./prep-demo.sh
|
|
60
|
-
```
|
|
39
|
+
Include the WASM module in your web page:
|
|
61
40
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
# Using Node.js
|
|
65
|
-
npx serve .
|
|
41
|
+
```javascript
|
|
42
|
+
import { resize_square } from "wasm-image-processor";
|
|
66
43
|
|
|
67
|
-
|
|
68
|
-
|
|
44
|
+
// Example: resize an image uploaded via <input type="file">
|
|
45
|
+
const fileInput = document.querySelector<HTMLInputElement>("#fileInput")!;
|
|
69
46
|
|
|
70
|
-
|
|
47
|
+
fileInput.addEventListener("change", () => {
|
|
48
|
+
const file = fileInput.files?.[0]
|
|
49
|
+
if (!file) return
|
|
71
50
|
|
|
72
|
-
|
|
51
|
+
const reader = new FileReader()
|
|
52
|
+
reader.onload = () => {
|
|
53
|
+
const arrayBuffer = reader.result as ArrayBuffer
|
|
54
|
+
const uint8Array = new Uint8Array(arrayBuffer)
|
|
73
55
|
|
|
74
|
-
|
|
56
|
+
// Resize to 512x512
|
|
57
|
+
const resizedBytes = resize_square(uint8Array, 512)
|
|
75
58
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
59
|
+
// Create a new File from the resized bytes
|
|
60
|
+
const resizedImage = new File([resizedBytes], "resized.png", {
|
|
61
|
+
type: "image/png",
|
|
62
|
+
})
|
|
79
63
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const imageData = new Uint8Array(/* your image data */);
|
|
83
|
-
const resizedBytes = resize_square(Array.from(imageData), 500);
|
|
64
|
+
console.log("Resized image:", resizedImage)
|
|
65
|
+
}
|
|
84
66
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
</script>
|
|
67
|
+
reader.readAsArrayBuffer(file)
|
|
68
|
+
})
|
|
88
69
|
```
|
|
89
70
|
|
|
90
71
|
### API Reference
|
|
@@ -146,9 +127,9 @@ The codebase is structured to easily add new image processing functions:
|
|
|
146
127
|
|
|
147
128
|
**Near Term:**
|
|
148
129
|
- [ ] Stable API design
|
|
149
|
-
- [
|
|
130
|
+
- [x] npm package publication
|
|
150
131
|
- [ ] Comprehensive documentation
|
|
151
|
-
- [
|
|
132
|
+
- [x] CI/CD pipeline
|
|
152
133
|
|
|
153
134
|
**Future Features:**
|
|
154
135
|
- [ ] Image format conversion (PNG ↔ JPEG ↔ WebP)
|
package/package.json
CHANGED
|
@@ -4,6 +4,12 @@ export function __wbg_set_wasm(val) {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
|
|
8
|
+
|
|
9
|
+
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
10
|
+
|
|
11
|
+
cachedTextDecoder.decode();
|
|
12
|
+
|
|
7
13
|
let cachedUint8ArrayMemory0 = null;
|
|
8
14
|
|
|
9
15
|
function getUint8ArrayMemory0() {
|
|
@@ -13,6 +19,11 @@ function getUint8ArrayMemory0() {
|
|
|
13
19
|
return cachedUint8ArrayMemory0;
|
|
14
20
|
}
|
|
15
21
|
|
|
22
|
+
function getStringFromWasm0(ptr, len) {
|
|
23
|
+
ptr = ptr >>> 0;
|
|
24
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
25
|
+
}
|
|
26
|
+
|
|
16
27
|
let WASM_VECTOR_LEN = 0;
|
|
17
28
|
|
|
18
29
|
function passArray8ToWasm0(arg, malloc) {
|
|
@@ -22,6 +33,12 @@ function passArray8ToWasm0(arg, malloc) {
|
|
|
22
33
|
return ptr;
|
|
23
34
|
}
|
|
24
35
|
|
|
36
|
+
function takeFromExternrefTable0(idx) {
|
|
37
|
+
const value = wasm.__wbindgen_export_0.get(idx);
|
|
38
|
+
wasm.__externref_table_dealloc(idx);
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
|
|
25
42
|
function getArrayU8FromWasm0(ptr, len) {
|
|
26
43
|
ptr = ptr >>> 0;
|
|
27
44
|
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
@@ -41,6 +58,9 @@ export function resize_square(image_data, side) {
|
|
|
41
58
|
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
|
|
42
59
|
const len0 = WASM_VECTOR_LEN;
|
|
43
60
|
const ret = wasm.resize_square(ptr0, len0, side);
|
|
61
|
+
if (ret[3]) {
|
|
62
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
63
|
+
}
|
|
44
64
|
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
45
65
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
46
66
|
return v2;
|
|
@@ -57,3 +77,8 @@ export function __wbindgen_init_externref_table() {
|
|
|
57
77
|
;
|
|
58
78
|
};
|
|
59
79
|
|
|
80
|
+
export function __wbindgen_string_new(arg0, arg1) {
|
|
81
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
82
|
+
return ret;
|
|
83
|
+
};
|
|
84
|
+
|
|
Binary file
|