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 framework.
For details see below.
Add this to your .pre-commit-config.yaml:
- repo: https://github.com/boidolr/pre-commit-images
rev: v1.10.0 # Use the ref you want to point at
hooks:
- id: optimize-png
# - id: ...
For an extended example see .pre-commit-config.yaml.
optimize-avif: Compressavifimages.--thresholdcan be used to configure which size difference should be used to keep the image.--qualityto configure minimum quality setting (best: 100, worst: 0).--effortto set the quality/speed tradeoff (slowest: 0, fastest: 10).
optimize-jpg: Compressjpegimages.--thresholdcan be used to configure which size difference should be used to keep the image.--qualitycan be used to configure quality setting for a JPG image.
optimize-png: Compresspngimages.--thresholdcan be used to configure which size difference should be used to keep the image.
optimize-svg: Compresssvgimages.--thresholdcan be used to configure which size difference should be used to keep the image.
optimize-webp: Compresswebpimages.--thresholdcan be used to configure which size difference should be used to keep the image.--losslessswitch to lossless compression.--qualitycan be used to configure quality setting for lossy compression or effort to spend on lossless compression.
resize(experimental): Resizeavif,jpeg,pngandwebpimages with fixed dimensions. Required options:--widthnew width of images.--heightnew height of images.
Install the package to get access to the scripts defined as command line entry points in 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' optimize-avif tests/test.avif.
Available entry points are identical to the pre-commit hooks:
optimize-avifoptimize-jpgoptimize-pngoptimize-svgoptimize-webpresize
These hooks only work because of other projects: