Skip to content

Scripts for image optimization usable as pre-commit hooks

License

Notifications You must be signed in to change notification settings

boidolr/pre-commit-images

Repository files navigation

pre-commit-images tag python Build pre-commit

Git hooks to optimize and manipulate images based on the pre-commit framework. For supported image formats see the list of available hooks 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.7.0  # Use the ref you want to point at
        hooks:
        -   id: optimize-png
        # -   id: ...

For an extended example see .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.

References

These hooks only work because of other projects: