Product
Introducing Java Support in Socket
We're excited to announce that Socket now supports the Java programming language.
The cwebp-bin npm package provides a Node.js wrapper for the cwebp command-line tool, which is used to convert images to the WebP format. This package allows developers to easily integrate WebP conversion into their Node.js applications.
Convert JPEG to WebP
This feature allows you to convert a JPEG image to WebP format using the cwebp command-line tool. The code sample demonstrates how to use the execFile function from the child_process module to execute the cwebp command with the input and output file paths.
const cwebp = require('cwebp-bin');
const { execFile } = require('child_process');
execFile(cwebp, ['input.jpg', '-o', 'output.webp'], err => {
if (err) {
throw err;
}
console.log('Image converted to WebP format');
});
Convert PNG to WebP
This feature allows you to convert a PNG image to WebP format using the cwebp command-line tool. The code sample demonstrates how to use the execFile function from the child_process module to execute the cwebp command with the input and output file paths.
const cwebp = require('cwebp-bin');
const { execFile } = require('child_process');
execFile(cwebp, ['input.png', '-o', 'output.webp'], err => {
if (err) {
throw err;
}
console.log('Image converted to WebP format');
});
Set WebP Quality
This feature allows you to set the quality of the output WebP image. The code sample demonstrates how to use the '-q' option with the cwebp command to specify the quality level (in this case, 80) for the output WebP image.
const cwebp = require('cwebp-bin');
const { execFile } = require('child_process');
execFile(cwebp, ['input.jpg', '-q', '80', '-o', 'output.webp'], err => {
if (err) {
throw err;
}
console.log('Image converted to WebP format with quality 80');
});
The imagemin-webp package is a plugin for the imagemin image optimization tool that allows you to convert images to the WebP format. It provides a higher-level API compared to cwebp-bin and integrates seamlessly with the imagemin ecosystem, making it easier to use in build processes and workflows.
The sharp package is a high-performance image processing library for Node.js that supports a wide range of image formats, including WebP. It provides a rich set of features for image manipulation, such as resizing, cropping, and format conversion. Compared to cwebp-bin, sharp offers more comprehensive image processing capabilities and a more user-friendly API.
The webp-converter package is a Node.js wrapper for the WebP conversion tools, similar to cwebp-bin. It provides functions to convert images to and from the WebP format. While it offers similar functionality to cwebp-bin, it also includes additional features such as batch conversion and support for animated WebP images.
WebP is a new image format that provides lossless and lossy compression for images on the web. WebP lossless images are 26% smaller in size compared to PNGs. WebP lossy images are 25-34% smaller in size compared to JPEG images at equivalent SSIM index.
You probably want imagemin-webp
instead.
$ npm install cwebp-bin
import {execFile} from 'node:child_process';
import cwebp from 'cwebp-bin';
execFile(cwebp, ['input.png', '-o', 'output.webp'], err => {
if (err) {
throw err;
}
console.log('Image is converted!');
});
$ npm install --global cwebp-bin
$ cwebp --help
MIT © Imagemin
FAQs
cwebp wrapper that makes it seamlessly available as a local dependency
The npm package cwebp-bin receives a total of 154,151 weekly downloads. As such, cwebp-bin popularity was classified as popular.
We found that cwebp-bin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers 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.
Product
We're excited to announce that Socket now supports the Java programming language.
Security News
Socket detected a malicious Python package impersonating a popular browser cookie library to steal passwords, screenshots, webcam images, and Discord tokens.
Security News
Deno 2.0 is now available with enhanced package management, full Node.js and npm compatibility, improved performance, and support for major JavaScript frameworks.