https://github.com/boidolr/pre-commit-images
Scripts for image optimization usable as pre-commit hooks
https://github.com/boidolr/pre-commit-images
avif git-hooks image-optimization jpeg png pre-commit svg
Last synced: 4 months ago
JSON representation
Scripts for image optimization usable as pre-commit hooks
- Host: GitHub
- URL: https://github.com/boidolr/pre-commit-images
- Owner: boidolr
- License: mit
- Created: 2022-01-12T18:52:29.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-05-29T13:59:26.000Z (4 months ago)
- Last Synced: 2025-05-29T15:01:43.673Z (4 months ago)
- Topics: avif, git-hooks, image-optimization, jpeg, png, pre-commit, svg
- Language: Python
- Homepage:
- Size: 610 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Citation: CITATION.cff
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
pre-commit-images
[](https://github.com/boidolr/pre-commit-images/tags)

[](https://github.com/boidolr/pre-commit-images/actions/workflows/continous-integration.yml)
[](https://github.com/pre-commit/pre-commit)
================Scripts that can work as `git` hooks to optimize and manipulate images.
These scripts can be called directly or with the provided configuration for the [pre-commit](https://github.com/pre-commit/pre-commit) framework.
For details see below.## Using pre-commit-images with pre-commit
Add this to your `.pre-commit-config.yaml`:
```
- repo: https://github.com/boidolr/pre-commit-images
rev: v1.8.8 # Use the ref you want to point at
hooks:
- id: optimize-png
# - id: ...
```
For an extended example see [`.pre-commit-config.yaml`](.pre-commit-config.yaml).### Available hooks
- **`optimize-avif`**: Compress `avif` images.
- `--threshold` can be used to configure which size difference should be used to keep the image.
- `--quality` to configure minimum quality setting (best: 100, worst: 0).
- `--effort` to set the quality/speed tradeoff (slowest: 0, fastest: 10).
- **`optimize-jpg`**: Compress `jpeg` images.
- `--threshold` can be used to configure which size difference should be used to keep the image.
- `--quality` can be used to configure quality setting for a JPG image.
- **`optimize-png`**: Compress `png` images.
- `--threshold` can be used to configure which size difference should be used to keep the image.
- **`optimize-svg`**: Compress `svg` images.
- `--threshold` can be used to configure which size difference should be used to keep the image.
- **`optimize-webp`**: Compress `webp` images.
- `--threshold` can be used to configure which size difference should be used to keep the image.
- `--lossless` switch to lossless compression.
- `--quality` can be used to configure quality setting for lossy compression or effort to spend on lossless compression.
- **`resize`** (experimental): Resize `avif`, `jpeg`, `png` and `webp` images with fixed dimensions. Required options:
- `--width` new width of images.
- `--height` new height of images.## Using scripts directly
Install the package to get access to the scripts defined as command line entry points in [`pyproject.toml`](./pyproject.toml).
The scripts accept the arguments given for the pre-commit hooks. Additionally they exepect to receive the file names to work on.An example invocation could be `uvx --from 'git+https://github.com/boidolr/pre-commit-images.git[avif]' optimize-avif tests/test.avif`.
Available entry points are identical to the pre-commit hooks:
- `optimize-avif`
- `optimize-jpg`
- `optimize-png`
- `optimize-svg`
- `optimize-webp`
- `resize`## References
These hooks only work because of other projects:
- [PIL](https://github.com/python-pillow/Pillow)
- [pillow-avif-plugin](https://github.com/fdintino/pillow-avif-plugin)
- [scour](https://github.com/scour-project/scour)