
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
webp-image-optimizer
Advanced tools
A lightweight Node.js tool to convert JPG, JPEG, and PNG images to WebP format with customizable quality settings. Significantly reduce image file sizes while maintaining visual quality for faster web performance.
# Install globally
npm install -g webp-image-optimizer
# Now you can use it from anywhere
webp-optimizer ./path/to/images
# Add to your project
npm install webp-image-optimizer
# Or with yarn
yarn add webp-image-optimizer
# Convert a single image
webp-optimizer path/to/image.jpg
# Convert a directory of images with default quality (80)
webp-optimizer path/to/directory
# Convert with custom quality setting (1-100)
webp-optimizer path/to/directory 60
# Convert without recursive directory scanning
webp-optimizer path/to/directory 80 false
const {
convertImageToWebP,
convertDirectoryImages,
} = require("webp-image-optimizer");
// Convert a single image
async function convertSingleImage() {
try {
const outputPath = await convertImageToWebP("./image.jpg", 75);
console.log(`Image converted successfully: ${outputPath}`);
} catch (error) {
console.error("Conversion failed:", error);
}
}
// Convert all images in a directory
async function convertAllImages() {
try {
await convertDirectoryImages("./images", 80, true);
console.log("All images converted successfully");
} catch (error) {
console.error("Directory conversion failed:", error);
}
}
You can add these scripts to your package.json:
"scripts": {
"optimize": "webp-optimizer ./images",
"optimize:60": "webp-optimizer ./images 60",
"optimize:80": "webp-optimizer ./images 80"
}
Converts a single image to WebP format.
imagePath (String): Path to the image filequality (Number, optional): Quality setting from 1-100, default is 80compareSize (Boolean, optional): If true, only saves WebP if smaller than original (default: true)Converts all compatible images in a directory.
directoryPath (String): Path to the directoryquality (Number, optional): Quality setting from 1-100, default is 80recursive (Boolean, optional): Process subdirectories if true (default: true)Before/after comparison for typical image types:
| Image Type | Original Size | WebP Size | Reduction |
|---|---|---|---|
| JPEG photo | 1.2 MB | 320 KB | 73% |
| PNG icon | 45 KB | 12 KB | 73% |
| PNG with transparency | 280 KB | 95 KB | 66% |
The optimizer uses the Sharp library to process images with the following approach:
MIT License
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
FAQs
A tool for converting and optimizing images to WebP format
The npm package webp-image-optimizer receives a total of 2 weekly downloads. As such, webp-image-optimizer popularity was classified as not popular.
We found that webp-image-optimizer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.