How to Convert WebP to JPG in Bulk Using PowerShell
Table of Contents
Introduction
WebP is a modern image format developed by Google that offers superior compression compared to traditional JPGs and PNGs. This results in smaller files, helping websites load faster. However, not all image editing software and devices fully support WebP yet. If you need to use your images with older tools or platforms, converting them to the universally-supported JPG format might be necessary. Here’s how to automate this process with PowerShell.
Prerequisites
- Windows PowerShell: This guide assumes you’re on a Windows system.
- WebP Encoder (cwebp.exe): Download the WebP command-line utilities from Google Developers (https://developers.google.com/speed/webp/download). You’ll need the
cwebp.exe
file. - WebP Images: A collection of WebP files you want to convert.
PowerShell Script
# Specify the folder containing your WebP files
$webpFolder = "C:\Your\WebP\Folder\Path"
# Path to the cwebp.exe file (modify if needed)
$cwebpPath = "C:\Path\To\Your\cwebp.exe"
# Get all WebP files in the folder
$webps = Get-ChildItem -Path $webpFolder -Filter "*.webp"
foreach ($webp in $webps) {
# Create output JPG filename
$jpgFileName = $webp.BaseName + ".jpg"
$jpgFilePath = Join-Path $webpFolder $jpgFileName
# Construct the command to run cwebp
$command = "& '{0}' '{1}' -o '{2}'" -f $cwebpPath, $webp.FullName, $jpgFilePath
# Execute the conversion command
Invoke-Expression $command
}
Explanation
Setting Folders: Replace placeholders with the path to your WebP folder and the location of your
cwebp.exe
file.Retrieving WebP Files: The code finds all
.webp
files in the specified folder.Generating JPG Names: The script creates an output JPG filename with the same base name as the input WebP file.
Constructing the cwebp Command: The script builds the command to execute the
cwebp.exe
utility to perform the conversion.Executing the Command: The
Invoke-Expression
command runs thecwebp
command, converting each WebP to JPG.
How to Run the Script
- Download cwebp.exe: Get it from Google Developers and place it in a convenient location.
- Open PowerShell: Find it in your Windows Start menu.
- Paste the Code: Paste the code into the PowerShell window.
- Modify Paths: Ensure the paths to your WebP folder and
cwebp.exe
are correct. - Execute: Press Enter to run the script.
Additional Tips
- Transparency: If you need to convert WebP images to JPG while preserving transparency, consider using PNG format instead. PNG offers both transparency and a wide color range.
More Image Conversions with PowerShell
Interested in automating other image conversion tasks? Check out these related guides:
- How to Convert PNG to JPG in Bulk Using PowerShell
- How to Convert GIF to JPG in Bulk Using PowerShell
Let me know if you have other image formats you’d like assistance converting with PowerShell!