wasm-image-processor 0.3.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 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://stanleymasinde.github.io/wasm-image-processor/](https://stanleymasinde.github.io/wasm-image-processor/)
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
- ## Building
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
- 3. Copy files to demo directory:
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
- 4. Serve the demo locally:
63
- ```bash
64
- # Using Node.js
65
- npx serve .
41
+ ```javascript
42
+ import { resize_square } from "wasm-image-processor";
66
43
 
67
- # Or any other static file server
68
- ```
44
+ // Example: resize an image uploaded via <input type="file">
45
+ const fileInput = document.querySelector<HTMLInputElement>("#fileInput")!;
69
46
 
70
- 5. Open `http://localhost:3000/demo` in your browser
47
+ fileInput.addEventListener("change", () => {
48
+ const file = fileInput.files?.[0]
49
+ if (!file) return
71
50
 
72
- ### Usage
51
+ const reader = new FileReader()
52
+ reader.onload = () => {
53
+ const arrayBuffer = reader.result as ArrayBuffer
54
+ const uint8Array = new Uint8Array(arrayBuffer)
73
55
 
74
- Include the WASM module in your web page:
56
+ // Resize to 512x512
57
+ const resizedBytes = resize_square(uint8Array, 512)
75
58
 
76
- ```html
77
- <script type="module">
78
- import init, { resize_square } from "pwa_image_generator";
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
- init().then(() => {
81
- // WASM module is ready
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
- // Use resizedBytes as needed
86
- });
87
- </script>
67
+ reader.readAsArrayBuffer(file)
68
+ })
88
69
  ```
89
70
 
90
71
  ### API Reference
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Stanley Masinde <hello@stanleymasinde.com>"
6
6
  ],
7
7
  "description": "High-performance client-side image processing toolkit powered by Rust and WebAssembly",
8
- "version": "0.3.0",
8
+ "version": "0.4.0",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
Binary file