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 +24 -43
- package/package.json +1 -1
- 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
|
package/package.json
CHANGED
|
Binary file
|