pixelhog

raw JSON →
1.2.0 verified Sat May 09 auth: no python

Rust-accelerated pixelmatch and SSIM for PNG bytes. Current version 1.2.0, active development, monthly releases.

pip install pixelhog
error AttributeError: module 'pixelhog' has no attribute 'diff'
cause The 'pixelhog.diff' submodule was removed in 1.0.0.
fix
Use 'from pixelhog import pixelmatch' directly.
error TypeError: expected bytes, not str
cause File path strings passed instead of PNG binary data.
fix
Read the file as bytes: open('file.png', 'rb').read()
breaking Version 1.0.0 removed the legacy 'pixelhog.diff' module. All functions are now top-level.
fix Use 'from pixelhog import pixelmatch' instead of 'from pixelhog.diff import pixelmatch'.
deprecated The 'webp_thumbnail' parameter in pixelmatch was added in 1.1.0, but the 'format' parameter is being replaced by 'output_format' in 2.0.
fix Use 'output_format' instead of 'format' when upgrading to 2.0.
gotcha Input must be raw PNG bytes (bytes object), not file paths or PIL images.
fix Open files in binary mode and pass the bytes: open('img.png', 'rb').read()

Compare two PNG byte strings and get diff image plus SSIM score.

from pixelhog import ssim, pixelmatch

png_a = open('a.png', 'rb').read()
png_b = open('b.png', 'rb').read()

# Compare two PNGs and get diff image bytes
diff_png, score = pixelmatch(png_a, png_b)
print(f'SSIM: {ssim(png_a, png_b)}')