repomatic.images moduleΒΆ
Image optimization using external CLI tools.
Tools used per format:
PNG:
oxipng(lossless, multithreaded Rust optimizer).JPEG/JPG:
jpegoptim(lossless Huffman optimization + metadata stripping).
Note
Both tools are strictly lossless: oxipng finds optimal PNG encoding
parameters without altering pixel data, and jpegoptim (without -m)
rewrites Huffman tables only. This means optimization is idempotent: a
second run produces no further changes, so the workflow never creates noisy
PRs for negligible savings.
Warning
WebP and AVIF are intentionally not optimized. The only available tools
(cwebp, avifenc) work by lossy re-encoding: decode, then re-compress at
a target quality. This is not idempotent: each pass re-compresses the
previous output, producing progressively smaller (and worse) files. A lossy
optimizer needs several workflow runs to settle below the savings threshold,
and each run opens a pull request with less to gain and more quality lost.
Lossless WebP/AVIF modes exist but typically increase file size when applied
to already lossy-encoded images, making them counterproductive. Since WebP and
AVIF are modern formats chosen specifically for their compression efficiency,
files in these formats are almost always already well-optimized at creation
time.
- repomatic.images.DEFAULT_MIN_SAVINGS_BYTES = 1024ΒΆ
Minimum absolute byte savings required to keep the optimized file.
- repomatic.images.DEFAULT_MIN_SAVINGS_PCT = 5ΒΆ
Minimum percentage savings required to keep the optimized file.
- repomatic.images.JPEGOPTIM_FLAGS = ('--strip-all', '--all-progressive')ΒΆ
Flags of every
jpegoptimrun: drop the metadata, write progressive JPEGs.
- repomatic.images.OXIPNG_OPT_LEVEL = '4'ΒΆ
Optimization level
oxipngruns at.
- class repomatic.images.OptimizationResult(path, before_bytes, after_bytes)[source]ΒΆ
Bases:
objectResult of optimizing a single image file.
- repomatic.images.optimize_image(path, min_savings_pct, min_savings_bytes=1024)[source]ΒΆ
Optimize a single image file in-place.
- Parameters:
path (
Path) β Path to the image file.min_savings_pct (
float) β Minimum percentage savings to keep the result. If savings are below this threshold, the original file is restored.min_savings_bytes (
int) β Minimum absolute byte savings to keep the result. Prevents noisy diffs for tiny files where even a high percentage represents negligible absolute savings.
- Return type:
- Returns:
An
OptimizationResultif the file was optimized, orNoneif the format is unsupported, the required tool is missing, or savings were below the threshold.