Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

node-webpmux

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-webpmux - npm Package Compare versions

Comparing version
3.1.6
to
3.1.7
+39
-1
examples.js

@@ -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",

@@ -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 />

@@ -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 = {