node-webpmux
Advanced tools
+39
-1
@@ -90,3 +90,3 @@ /* | ||
| // Or for all the frames to disk | ||
| await anim.demux('directory/to/place/then'); | ||
| await anim.demux('directory/to/place/them'); | ||
@@ -99,1 +99,39 @@ // To export to a Buffer instead. Supports the three variants described for .demux() above | ||
| img.exif = fs.readFileSync('metadata.exif'); | ||
| // For a quick-and-dirty way to set frame data via a Worker for a moderate speed-up from threaded saving. This example is using NodeJS Workers, but should also work via Web Workers in a browser. | ||
| // saver.js | ||
| const { Worker } = require('worker_threads'); | ||
| const WebP = require('node-webpmux'); | ||
| function spawnWorker(data) { | ||
| return new Promise((res, rej) => { | ||
| let worker = new Worker('saver.worker.js', { workerData: data }); | ||
| worker.on('message', res); | ||
| worker.on('error', rej); | ||
| worker.on('exit', (code) => { if (code != 0) { rej(new Error(`Worker stopped with exit code ${code}`)); } }); | ||
| }); | ||
| } | ||
| async function go() { | ||
| let img = await WebP.Image.load('anim.webp'), newFrames = [], promises = []; | ||
| /* populate newFrames via getFrameData and make changes as desired */ | ||
| for (let i = 0, { frames } = img.data, l = frames.length; i < l; i++) { | ||
| promises.push(spawnWorker({ webp: img, frame: i, data: newFrames[i] }).then((newdata) => { img.data.frames[i] = newdata; })); | ||
| } | ||
| await Promise.all(promises); | ||
| await img.save('newanim.webp'); | ||
| } | ||
| go().then(/* ... */)' | ||
| // saver.worker.js | ||
| const { parentPort, workerData } = require('worker_threads'); | ||
| const WebP = require('node-webpmux'); | ||
| async function saveFrame(d) { | ||
| let { data, frame, webp } = d; | ||
| let img = WebP.Image.from(webp); | ||
| await WebP.Image.initLib(); | ||
| await img.setFrameData(frame, data, { lossless: 9 }); | ||
| return img.data.frames[frame]; | ||
| } | ||
| parentPort.postMessage(await saveFrame(workerData)); |
+1
-1
| { | ||
| "name": "node-webpmux", | ||
| "version": "3.1.6", | ||
| "version": "3.1.7", | ||
| "description": "A pure Javascript/WebAssembly re-implementation of webpmux", | ||
@@ -5,0 +5,0 @@ "main": "webp.js", |
+5
-0
@@ -248,2 +248,7 @@ # node-webpmux | ||
| ##### `Image.from(webp)` | ||
| Use the contents of `webp` and return a new Image using them.<br /> | ||
| Mainly useful for passing Image into a Web Worker or NodeJS Worker and converting the passed object back into an Image instance.<br /> | ||
| Such an approach can be used to greatly speed up saving of animations or multiple images as libwebp is *not* multi-threaded beyond saving the alpha layer of lossy images. | ||
| ##### `async Image.save(path, options)` | ||
@@ -250,0 +255,0 @@ Save the `options` using `Image.getEmptyImage()`.<br /> |
+7
-0
@@ -398,2 +398,9 @@ // For more information on the WebP format, see https://developers.google.com/speed/webp/docs/riff_container | ||
| } | ||
| static from(webp) { | ||
| let img = new Image(); | ||
| img.data = webp.data; | ||
| img.loaded = webp.loaded; | ||
| img.path = webp.path; | ||
| return img; | ||
| } | ||
| } | ||
@@ -400,0 +407,0 @@ module.exports = { |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
517444
0.39%1248
3.31%424
1.19%