image_to_webp 1.0.0
image_to_webp: ^1.0.0 copied to clipboard
Convert PNG/JPG images to WebP using a webp.yaml config file (CLI + API).
image_to_webp #
Convert PNG/JPG images to WebP using a webp.yaml config file.
Features #
- Works as a Dart CLI:
dart run image_to_webp - Config-driven: define folders in
webp.yaml - Two scan modes:
some_dir/*converts only files directly inside the foldersome_dir/**converts recursively (including subfolders)
- Progress output in the terminal (percent + counters)
- Optional cleanup:
-d/--deletedeletes source images after converting
Requirements #
- Usually: nothing to install. The tool uses a bundled
cwebpbinary shipped via the Dart dependency. - Fallback: if your architecture isn’t bundled, it will try
cwebpfrom your$PATH.
Installing cwebp (only if fallback is needed) #
macOS (Homebrew):
brew install webp
Ubuntu/Debian:
sudo apt-get update && sudo apt-get install -y webp
Windows (Chocolatey):
choco install webp
Installation #
Add it to your dev dependencies:
dart pub add --dev image_to_webp
Usage (CLI) #
Create webp.yaml in the project root where you run the command:
paths:
- assets/* # only files directly inside assets/
- assets/** # recursively
quality: 80 # optional, default: 80 (0..100)
Run:
dart run image_to_webp
Delete originals after successful conversion:
dart run image_to_webp -d
Usage (Dart API) #
You can also call the same logic programmatically:
import 'dart:io';
import 'package:image_to_webp/image_to_webp.dart';
Future<void> main() async {
final code = await runImageToWebp(
const ['--config', 'webp.yaml'],
stdout: stdout,
stderr: stderr,
);
if (code != 0) exit(code);
}
Example project #
See example/main.dart.
Notes #
- Outputs
*.webpalongside the original file (same folder, same basename). - Skips files that are already WebP.