@keeratita/heic-converter 0.1.0 → 0.2.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
@@ -25,6 +25,16 @@ npm install @keeratita/heic-converter
25
25
 
26
26
  ---
27
27
 
28
+ ## 🌍 Live Demo (GitHub Pages)
29
+
30
+ Try the browser demo here:
31
+
32
+ https://keeratita.github.io/heic-converter/
33
+
34
+ The demo is auto-deployed from the `main` branch by the GitHub Actions workflow in `.github/workflows/demo-pages.yml`.
35
+
36
+ ---
37
+
28
38
  ## 🚀 Usage
29
39
 
30
40
  ### 1. Browser: Simple Conversion
@@ -48,7 +58,7 @@ document.querySelector('img').src = imageUrl;
48
58
 
49
59
  ### 2. Browser: Serving and Locating WASM (Custom Assets Path)
50
60
 
51
- By default, the library tries to fetch `heic-decoder.wasm` relative to the current module script path (`import.meta.url`).
61
+ By default, the library tries to fetch `heic-decoder.wasm` relative to the current module script path (`import.meta.url`).
52
62
 
53
63
  If your bundler places files in a custom assets folder or CDN, you can configure the default decoder or inject a custom one:
54
64
 
@@ -57,13 +67,13 @@ import { convertHeic, LibheifDecoder } from '@keeratita/heic-converter';
57
67
 
58
68
  // Create decoder with custom asset paths
59
69
  const decoder = new LibheifDecoder({
60
- locateFile: (path, prefix) => `https://cdn.example.com/assets/${path}`
70
+ locateFile: (path, prefix) => `https://cdn.example.com/assets/${path}`,
61
71
  });
62
72
 
63
73
  // Pass the custom decoder in options
64
74
  const pngBlob = await convertHeic(heicBlob, {
65
75
  to: 'png',
66
- decoder: decoder
76
+ decoder: decoder,
67
77
  });
68
78
  ```
69
79
 
@@ -79,13 +89,13 @@ const decoder = new LibheifDecoder({ wasmBinary });
79
89
 
80
90
  const jpegBlob = await convertHeic(heicBlob, {
81
91
  to: 'jpeg',
82
- decoder: decoder
92
+ decoder: decoder,
83
93
  });
84
94
  ```
85
95
 
86
96
  ### 3. Node.js: Decoding Raw Pixel Data
87
97
 
88
- Since Node.js lacks the native browser Canvas API, `convertHeic` (which relies on Canvas to encode raster formats) will throw an error on the backend.
98
+ Since Node.js lacks the native browser Canvas API, `convertHeic` (which relies on Canvas to encode raster formats) will throw an error on the backend.
89
99
 
90
100
  However, you can use the `LibheifDecoder` in Node.js to retrieve the raw RGBA pixels and then encode them using libraries like `sharp` or `pngjs`:
91
101
 
@@ -96,20 +106,20 @@ import sharp from 'sharp'; // external node image library
96
106
 
97
107
  async function convertNode() {
98
108
  const heicData = new Uint8Array(fs.readFileSync('input.heic'));
99
-
109
+
100
110
  const decoder = new LibheifDecoder();
101
111
  await decoder.initialize();
102
-
112
+
103
113
  // Decodes to { width, height, data: Uint8ClampedArray (RGBA) }
104
114
  const { width, height, data } = await decoder.decode(heicData);
105
-
115
+
106
116
  // Process raw pixels using sharp
107
117
  await sharp(Buffer.from(data.buffer), {
108
- raw: { width, height, channels: 4 }
118
+ raw: { width, height, channels: 4 },
109
119
  })
110
- .toFormat('jpeg')
111
- .toFile('output.jpg');
112
-
120
+ .toFormat('jpeg')
121
+ .toFile('output.jpg');
122
+
113
123
  // Clean up WASM memory
114
124
  decoder.free();
115
125
  }
@@ -194,47 +204,58 @@ freeSharedDecoder();
194
204
  If you want to build or modify the WASM wrapper, you will need **Docker** installed.
195
205
 
196
206
  ### Build WebAssembly
207
+
197
208
  To compile the underlying `libheif` and `libde265` libraries from source using Emscripten:
209
+
198
210
  ```bash
199
211
  npm run build:wasm
200
212
  ```
201
213
 
202
214
  ### Build JS & TS Typings
215
+
203
216
  To compile the TypeScript library code to ESM/CJS bundles under the `dist/` directory:
217
+
204
218
  ```bash
205
219
  npm run build
206
220
  ```
207
221
 
208
222
  ### Run Unit Tests
223
+
209
224
  ```bash
210
225
  npm run test
211
226
  ```
212
227
 
213
228
  ### Run Interactive CSP Sandbox
229
+
214
230
  To test the converter in a local browser running under a strict Content Security Policy, start the sandbox server:
231
+
215
232
  ```bash
216
233
  npm run sandbox
217
234
  ```
235
+
218
236
  Then navigate to: `http://localhost:3000`
219
237
 
220
238
  ### Release / Versioning
239
+
221
240
  To bump the package version (following SemVer) and push the release commits/tags to the git remote:
241
+
222
242
  ```bash
223
243
  npm run release
224
244
  ```
245
+
225
246
  Alternatively, you can pass the release type as an argument:
247
+
226
248
  ```bash
227
249
  npm run release patch
228
250
  npm run release minor
229
251
  npm run release major
230
252
  npm run release current
231
253
  ```
232
- This script will automatically run the linter, build the TS library, run the unit tests. For `patch`, `minor`, and `major`, it bumps the version (updating `package.json`/`package-lock.json`), commits the changes with a Conventional Commit message (`chore(release): X.Y.Z`), tags the commit, and pushes both the commit and tag to the remote. For `current`, it simply tags the current commit with the existing version in `package.json` (e.g. `vX.Y.Z`) and pushes that tag to the remote without committing or altering files.
233
254
 
255
+ This script will automatically run the linter, build the TS library, run the unit tests. For `patch`, `minor`, and `major`, it bumps the version (updating `package.json`/`package-lock.json`), commits the changes with a Conventional Commit message (`chore(release): X.Y.Z`), tags the commit, and pushes both the commit and tag to the remote. For `current`, it simply tags the current commit with the existing version in `package.json` (e.g. `vX.Y.Z`) and pushes that tag to the remote without committing or altering files.
234
256
 
235
257
  ---
236
258
 
237
259
  ## 📄 License
238
260
 
239
261
  MIT © Keerati Tansawatcharoen
240
-