def _images_are_similar(img1_bytes, img2_bytes, max_pct_diff=1.0, pixel_threshold=10):
    """
    Compare two images and determine if the percentage of differing pixels is below a threshold.

    :param img1_bytes: Byte content of the first image.
    :param img2_bytes: Byte content of the second image.
    :param max_pct_diff: Maximum allowed percentage of differing pixels.
    :param pixel_threshold: Per-pixel difference threshold to consider a pixel as different.
    :return: Boolean indicating if images are similar within the allowed percentage difference.
    """
    img1 = Image.open(io.BytesIO(img1_bytes)).convert("RGB")
    img2 = Image.open(io.BytesIO(img2_bytes)).convert("RGB")

    if img1.size != img2.size:
        print(f"Image sizes do not match: {img1.size} vs {img2.size}")
        return False

    diff = ImageChops.difference(img1, img2)

    diff_gray = diff.convert("L")

    differing_pixels = sum(
        1 for pixel in diff_gray.getdata() if pixel > pixel_threshold
    )
    total_pixels = img1.size[0] * img1.size[1]
    pct_diff = (differing_pixels / total_pixels) * 100

    print(f"Percentage of differing pixels: {pct_diff:.2f}%")
    return pct_diff <= max_pct_diff

    Compare two images and determine if the percentage of differing pixels is below a threshold.

    :param img1_bytes: Byte content of the first image.
    :param img2_bytes: Byte content of the second image.
    :param max_pct_diff: Maximum allowed percentage of differing pixels.
    :param pixel_threshold: Per-pixel difference threshold to consider a pixel as different.
    :return: Boolean indicating if images are similar within the allowed percentage difference.
    
src/tests/text/pdf_miner/test_core.py