lovell / avif-cli Goto Github PK
View Code? Open in Web Editor NEWCommand line utility to convert images to AVIF
License: Apache License 2.0
Command line utility to convert images to AVIF
License: Apache License 2.0
package.json:
"devDependencies": {
"avif": "latest"
}
Running npm install
using npm v7.20.5 gives me
npm ERR! code 1
npm ERR! path /home/test/node_modules/sharp
npm ERR! command failed
npm ERR! command sh -c (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
npm ERR! make: Entering directory '/home/test/node_modules/sharp/build'
npm ERR! TOUCH Release/obj.target/libvips-cpp.stamp
npm ERR! CXX(target) Release/obj.target/sharp/src/common.o
npm ERR! make: Leaving directory '/home/test/node_modules/sharp/build'
npm ERR! info sharp Using cached /home/test/.npm/_libvips/libvips-8.9.0-linux-x64.tar.gz
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | linux | x64
npm ERR! gyp info find Python using Python version 3.9.6 found at "/usr/bin/python3"
npm ERR! (node:67730) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
npm ERR! (Use `node --trace-deprecation ...` to show where the warning was created)
npm ERR! gyp info spawn /usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args '/home/test/.npm-global/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args 'binding.gyp',
npm ERR! gyp info spawn args '-f',
npm ERR! gyp info spawn args 'make',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/home/test/node_modules/sharp/build/config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/home/test/.npm-global/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/home/test/.cache/node-gyp/16.6.1/include/node/common.gypi',
npm ERR! gyp info spawn args '-Dlibrary=shared_library',
npm ERR! gyp info spawn args '-Dvisibility=default',
npm ERR! gyp info spawn args '-Dnode_root_dir=/home/test/.cache/node-gyp/16.6.1',
npm ERR! gyp info spawn args '-Dnode_gyp_dir=/home/test/.npm-global/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args '-Dnode_lib_file=/home/test/.cache/node-gyp/16.6.1/<(target_arch)/node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=/home/test/node_modules/sharp',
npm ERR! gyp info spawn args '-Dnode_engine=v8',
npm ERR! gyp info spawn args '--depth=.',
npm ERR! gyp info spawn args '--no-parallel',
npm ERR! gyp info spawn args '--generator-output',
npm ERR! gyp info spawn args 'build',
npm ERR! gyp info spawn args '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! <command-line>: warning: "_GLIBCXX_USE_CXX11_ABI" redefined
npm ERR! <command-line>: note: this is the location of the previous definition
npm ERR! In file included from /home/test/.cache/node-gyp/16.6.1/include/node/v8.h:30,
npm ERR! from /home/test/.cache/node-gyp/16.6.1/include/node/node.h:63,
npm ERR! from ../src/common.cc:22:
npm ERR! /home/test/.cache/node-gyp/16.6.1/include/node/v8-internal.h: In function ‘void v8::internal::PerformCastCheck(T*)’:
npm ERR! /home/test/.cache/node-gyp/16.6.1/include/node/v8-internal.h:488:38: error: ‘remove_cv_t’ is not a member of ‘std’; did you mean ‘remove_cv’?
npm ERR! 488 | !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
npm ERR! | ^~~~~~~~~~~
npm ERR! | remove_cv
npm ERR! /home/test/.cache/node-gyp/16.6.1/include/node/v8-internal.h:488:38: error: ‘remove_cv_t’ is not a member of ‘std’; did you mean ‘remove_cv’?
npm ERR! 488 | !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
npm ERR! | ^~~~~~~~~~~
npm ERR! | remove_cv
npm ERR! /home/test/.cache/node-gyp/16.6.1/include/node/v8-internal.h:488:50: error: template argument 2 is invalid
npm ERR! 488 | !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
npm ERR! | ^
npm ERR! /home/test/.cache/node-gyp/16.6.1/include/node/v8-internal.h:488:63: error: ‘::Perform’ has not been declared
npm ERR! 488 | !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
npm ERR! | ^~~~~~~
npm ERR! make: *** [sharp.target.mk:139: Release/obj.target/sharp/src/common.o] Error 1
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack at ChildProcess.onExit (/home/test/.npm-global/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:394:28)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
npm ERR! gyp ERR! System Linux 5.13.0-14-generic
npm ERR! gyp ERR! command "/usr/bin/node" "/home/test/.npm-global/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /home/test/node_modules/sharp
npm ERR! gyp ERR! node -v v16.6.1
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok
Despite passing --overwrite
, running bunx avif --verbose --input="${filename}" --effort=9 --quality=60 --overwrite
gives "Cannot use same file for input and output"
I am running avif-cli like this: avif --input='img/*.{jpg,jpeg,png}' --quality 64 --verbose
. This works fine, when at least one image will be converted. When all images already have been converted and --overwrite
has not been set, avif will return with a status of 1
which will be interpreted as failure.
The culprit seems to be this line, which returns undefined
in this case.
https://github.com/lovell/avif-cli/blob/main/lib/convert.js#L33
Changing it for example to return true
would fix this issue.
Can this be used to convert an mp4 to an animated avif?
This feels like it's a pretty generic error that might be due to something else... but I'll ask anyway.
Building a fresh environment with this Dockerfile:
FROM ubuntu:latest
RUN apt-get update && apt-get -y upgrade && apt-get -y install curl && \
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash && \
export NVM_DIR="$HOME/.nvm" && \
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && \
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && \
nvm install node && \
npx -y avif # install avif
I get the following at the end of the procedure:
Downloading and installing node v19.5.0...
Downloading https://nodejs.org/dist/v19.5.0/node-v19.5.0-linux-x64.tar.gz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v19.5.0 (npm v9.3.1)
Creating default alias: default -> node (-> v19.5.0 *)
Illegal instruction (core dumped)
I've tried doing it step-by-step as well. NPM otherwise seems to be responding correctly, though I'm more of a PHP person and might be missing something really obvious.
What information might be helpful to further diagnose?
I think that the current implementation is pretty confusing.
If we want the output-dir to be the same as input dir we have to provide an empty output-dir as a parameter, like: avif --input="..." --output=""
I guess that's confusing UX. It would be better when the default output-dir would be the input dir itself, especially when input dir is a glob pattern.
I have opened a PR for it, #6
Thanks for writing this script!
When using
npx avif --input="/path/to/www/assets/**/*.*" --output=/path/to/www/assets-avif --verbose
It would be really nice if there was a built-in way to preserve the input directory structure in the output directory.
We don't want to save the AVIFs to the same folder as the source images as the CMS media browser will show both, but for easy try_files
configuration we'd like to mirror the directory structure in the destination. Plus it keeps the folders with a manageable number of images in them.
Example:
/path/to/www/assets/images/foo/bar/baz.jpg => /path/to/www/assets-avif/images/foo/bar/baz.avif
(Having an option to append .avif
would also be cool, to mirror how our bash script has been doing it. So the output file name is baz.jpg.avif
. That way the try_files
usage stays simple.
example gif animated file:
https://mega.nz/file/0zkXkApB#v4tAPp_qV-OiWnsRwDC1Brwwv_tgf8C-LemVbE7Eobg
reference:
FYI, I got an error from require("fs/promises")
- mentioned in this stack-overflow question when trying to run npx avif
with node version 12.13.1
Looks like you may need node > 12.19
Feel free to close this issue if you want, I am just mentioning it b/c you said "requires Node.js 10+" in the Readme :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.