npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

webp-batch-convert

v1.0.1

Published

webp 图片批量转换。将指定目录内 png/jpg/jpeg/bmp/gif 格式的图片批量转换为 webp 格式。

Downloads

55

Readme

webp-batch-convert

Webp Batch Convert

webp 图片批量转换。将指定目录内 png/jpg/jpeg/bmp/gif 格式的图片批量转换为 webp 格式。

NPM version node version npm download GitHub issues GitHub forks GitHub stars minzipped size

快速上手

在项目目录中安装

npm install --save-dev webp-batch-convert
npm exec wbc -h

使用示例(nodejs 模块 API 方式)

//import convert from 'webp-batch-convert';
const convert = require('webp-batch-convert');
let res;

// 示例一: 生成 img 目录下的图片文件至 webp 目录
res = await convert.cwebp('./img', './webp');
console.log('total: ', res);

// 示例二: 生成 img 目录下的图片文件至 webp 目录,附带质量等参数
// 更多参数参考:https://developers.google.com/speed/webp/docs/cwebp?csw=1#options
// 也可以执行如下命令通过 cwebp 帮助信息了解: `yarn cwebp --longhelp`
const cwebpOpts = {
    /** don't print anything */
    quiet: true,
    /** quality factor (0:small..100:big), default=75 */
    q: 75,
    /** transparency-compression quality (0..100), default=100 */
    alpha_q: 100,
    /** spatial noise shaping (0:off, 100:max), default=50 */
    sns: 50,
    /** filter strength (0=off..100), default=60 */
    f: 60,
    /** use simple filter instead of strong */
    nostrong: false,
};
// 先清空输出目录
convert.utils.delDir('./webp');
res = await convert.cwebp('./img','./webp', cwebpOpts);
console.log('total: ', res);

best-practice

命令行方式使用(wbc / cwebp-batch)

全局安装

npm install -g webp-batch-convert
wbc -h
# or 
cwebp-batch -h

也可以不安装,使用 npx 执行:

npx webp-batch-convert -h

使用示例

wbc --in img-folder --out webp-folder <--debug --q 75>

或者局部安装,然后如下方式使用:

./node_modules/.bin/wbc --in img-folder --out webp-folder <-D -q 75>

API

  • .cwebp(imgDir, webpDir, cwebpOptions)

批量转换生成 webp。示例:

// 将 img 目录下的所有图片转换为 webp 文件,输出至 webp 目录
const res = await convert.cwebp('./img','./webp', {
    debug: true,
    q: 60        // 质量
});
console.log('result: ' + res);
  • .utils.mkDir(dirPath)

创建一个(深度的)目录。示例:

// 创建目录
convert.utils.mkDir('./src/assets/webp');
  • .utils.delDir(dirPath, ext)

清空一个(非空的)目录。示例:

// 删除 webp 目录
convert.utils.delDir('./webp');
// 删除 webp 目录下的所有 webp 后缀的文件
convert.utils.delDir('./webp', 'webp');
// 删除 webp 目录下的所有 .webp、png 后缀的文件
convert.utils.delDir('./webp', /\.(webp|png)$/);

二次开发

  • 依赖安装 pnpm install
  • 修改/新增功能
  • 添加测试并执行 pnpm test
  • 全局安装与测试 npm link . && wbc -h

License

webp-batch-convert is released under the MIT license.

该插件由志文工作室开发和维护。