importing jpegasm error
pfeatherstone opened this issue · 1 comments
pfeatherstone commented
I'm using jpegasm in a vue application. when calling
import jpegasm from 'jpeg-asm'
or
var jpegasm = require('jpeg-asm');
i get runtime error:
TypeError: r.cwrap is not a function
at Object.ea24 (api.js:10)
at i (bootstrap:79)
gchudnov commented
I hope after library update this is not a problem anymore.
at least cannot see these errors:
const jpegasm = require('jpeg-asm');
const fs = require('fs');
const filepath = 'SOME_IMAGE';
const jpegBuffer = fs.readFileSync(filepath);
const jpegArray = new ArrayBuffer(jpegBuffer.length);
const jpegView = new Uint8Array(jpegArray);
for(let i = 0; i !== jpegBuffer.length; ++i) {
jpegView[i] = jpegBuffer[i];
}
jpegasm.decode(jpegArray, (err, data) => {
console.log({ err, data });
const options = {
width: data.width,
height: data.height,
quality: 80
};
jpegasm.encode(data.buffer, options, (err, data) => {
console.log({ err, data });
})
});
the only point - API is async now due to the way WASM starts up.