-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Node.js API #934
Comments
Yup, at some point I want to re-factor the CLI to have a proper separation between a |
Yep, it will be great, this would take image optimization to a new level, hoping it will come in the near future, |
& deno compat importing also please :) |
@alexander-akait in the meanwhile, you can use const { exec } = require("child_process")
let file = './img/codepen.io-2021-02-15.png'
let rounds = 2
let bt = 1.1
exec(`squoosh-cli -s .r${rounds}bt${bt} --avif --max-optimizer-rounds ${rounds} --optimizer-butteraugli-target ${bt} -d out ${file}`, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`🎆 success!
${stdout}`);
}) |
My above code doesn't work when launched in Window's git-bash, but this one does! Just have to use npm & not have good error reporting: |
@surma I need this badly enough that I'm willing to yank the source code and manually frankenstein it into my project. If you are up for it, I would much rather spend that time making a PR here that adds an official I'm not too worried that I will implement it differently from what you have in mind, since it's all experimental, so you can always redesign it when you have time for it. I think most of us are okay with a basic and unstable API, we just want something as soon as possible :) |
@atjn That’d be amazing. Happy to review a PR! |
@surma there you go, hope you like it! |
Is your feature request related to a problem? Please describe.
squoosh
has CLI, so I think it is possible to implement Node.js APIDescribe the solution you'd like
Adding Node.js API
Does other service/app have this feature?
For example -
imagemin
have CLI and Node.js APIAdditional context
The Node.js API will allow
squoosh
to be used in other tools, for example I am developers https://github.com/webpack-contrib/image-minimizer-webpack-plugin and now we useimagemin
for this, but setup is complex and unable on some platform because libraries for compression compiled on developer machineThe text was updated successfully, but these errors were encountered: