Skip to content

A small script to batch convert images to WebP format πŸ–Ό

License

Notifications You must be signed in to change notification settings

PiotrRut/WebP-Batch-Convert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Batch WebP Converter

I had two reasons for writing this piece of code:

  • Google's cwebp command only lets you compress and convert one file at a time, which is often very tedious with a larger set of files.
  • I could've done this very easily in Python, but where's the fun in that? I wanted to learn shell, and what better way to do it than by solving a problem I have just created πŸ™ŒπŸΌ

You need the webp formula installed through Homebrew to use this script. Alternatively, you can download and run the cwebp excutable, which this program can automatically download and configure for you, should you desire. It can also be manually downloaded for your OS from here - the latest version is 1.1.0.

For all available options, visit Google's docs.

Usage - Bash/Zsh πŸ‘¨πŸ»β€πŸ’»

First, make the file executable by running

$ chmod +x convert.sh

Then, run the scrip in current working directory

~WebP-Batch-Converter $ ./convert.sh

After going through the installation process (should you not have webp installed on your machine already), you will be asked to provide an input directory with all your image files. You will also be asked to provide a compression factor.

# This will take folder named "files" located in the same working directory
"Where are your images located? Provide folder:" > ./files

Converted WebP files will be put in the script's working directory

# Example state after execution:

β”œβ”€β”€ convert.sh
β”œβ”€β”€ file1.webp
└── file2.webp

Usage - PowerShell πŸ‘¨πŸ»β€πŸ’»

Big thanks to Reece Mercer for contributing the PowerShell solution!

ConvertTo-Webp.ps1 [-downloadLibWebp] [[-compressionFactor] <Int32>] [-directory] <String> [<CommonParameters>]

The script takes a switch (-downloadLibWebp) that enables the download of the cwebp binary if it isn't already installed and on the system path, otherwise it will just try to call the system's copy. It will run this executable over every file in -directory. The output file format is the same as the Bash/Zsh version.

-compressionFactor is defaulted to 80 but can be overridden.

For a full Comment-Based Help output, run:

Get-Help ./ConvertTo-Webp.ps1 -Full

About

A small script to batch convert images to WebP format πŸ–Ό

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published