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 Common errors
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()
Warnings
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()
Imports
- ssim wrong
import pixelhog.ssimcorrectfrom pixelhog import ssim - pixelmatch wrong
from pixelhog.diff import pixelmatchcorrectfrom pixelhog import pixelmatch - Comparison
from pixelhog import Comparison
Quickstart
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)}')