view tests/test_rewrite_images.py @ 31:baeb8bdeff3a

Fortify sources using _FORTIFY_SOURCE=3 and also apply -fno-delete-null-pointer-checks. See: https://github.com/ossf/wg-best-practices-os-developers/issues/659.
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 21 Sep 2025 13:11:30 +0200
parents 1d09e1dec1d9
children
line wrap: on
line source

import pymupdf
import os

scriptdir = os.path.dirname(__file__)


def test_rewrite_images():
    """Example for decreasing file size by more than 30%."""
    filename = os.path.join(scriptdir, "resources", "test-rewrite-images.pdf")
    doc = pymupdf.open(filename)
    size0 = os.path.getsize(doc.name)
    doc.rewrite_images(dpi_threshold=100, dpi_target=72, quality=33)
    data = doc.tobytes(garbage=3, deflate=True)
    size1 = len(data)
    assert (1 - (size1 / size0)) > 0.3