This guide will walk you through installing and using the WebP converter tool globally on your system.
-
Create a new directory for your project:
mkdir webpconvert cd webpconvert -
Save the
webpconvert.jsandpackage.jsonfiles to this directory. -
Make the script executable:
chmod +x webpconvert.js- Install the dependencies:
npm install- Install the package globally:
npm install -g .Note: You might need to use sudo on Linux / Mac:
sudo npm install -g .Once installed, you can run the webpconvert command from anywhere on your system:
webpconvert image.webpThis will convert image.webp to JPG and save it in aconverted folder in the same directory.
webpconvert image.webp -f png
# OR
webpconvert image.webp -f pYou can use -f or --format followed byjpg, png, j(shorthand for jpg), orp(shorthand for png).
webpconvert -i /path/to/imagesThis will convert all WebP files in the specified directory and save them to an output folder with a timestamp.
webpconvert --help# Convert a single WebP file to JPG
webpconvert my-image.webp
# Convert a single WebP file to PNG
webpconvert my-image.webp -f png
# OR shorthand
webpconvert my-image.webp -f p
# Convert all WebP files in the current directory
webpconvert -i .
# Convert all WebP files in a specific directory to PNG
webpconvert -i ~/Pictures/webp-images -f pngIf you encounter any issues:
- Make sure the sharp library is properly installed:
npm install sharp- Check that the script has executable permissions:
chmod +x webpconvert.js- If you get a "command not found" error, make sure the global npm bin directory is in your PATH.