Skip to content

PageObject.images compresses JPEG images with only 75% quality, and there is no option to control this #3515

@Lucas-C

Description

@Lucas-C

Hi!

I'm a maintainer of pdfly, that has an extract-images subcommand, that uses PageObject.images internally.

Recently, a user reported an image compression issue: py-pdf/pdfly#200

I investigated and I think I found what happens:

Suggested bug fix

In _xobj_to_image(), pypdf could simply provide an extra quality="keep" to Image.save().

IMHO this seems like the best default value,
even if that means a non-fully-backward-compatible change to pypdf.

Feature request

Could it be also possible to introduce a way to provide a custom value for this quality parameter provided to Image.save(), please?

Ideally a new optional argument would be great, but I don't quite see how to make this works with the PageObject.images property that returns a VirtualListImages...

Maybe through a global variable ?
Or through a new parameter of PdfReader?

Metadata

Metadata

Assignees

No one assigned

    Labels

    is-bugFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDFworkflow-imagesFrom a users perspective, image handling is the affected feature/workflow

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions