Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STY: Slight refactor of remove_images #2979

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2194,29 +2194,19 @@ def remove_images(
Remove images from this output.

Args:
to_delete : The type of images to be deleted
to_delete: The type of images to be deleted
(default = all images types)

"""
if isinstance(to_delete, bool):
to_delete = ImageType.ALL
i = (
(
ObjectDeletionFlag.XOBJECT_IMAGES
if to_delete & ImageType.XOBJECT_IMAGES
else ObjectDeletionFlag.NONE
)
| (
ObjectDeletionFlag.INLINE_IMAGES
if to_delete & ImageType.INLINE_IMAGES
else ObjectDeletionFlag.NONE
)
| (
ObjectDeletionFlag.DRAWING_IMAGES
if to_delete & ImageType.DRAWING_IMAGES
else ObjectDeletionFlag.NONE
)
)

i = ObjectDeletionFlag.NONE

for image in ("XOBJECT_IMAGES", "INLINE_IMAGES", "DRAWING_IMAGES"):
if to_delete & ImageType[image]:
i |= ObjectDeletionFlag[image]

for page in self.pages:
self.remove_objects_from_page(page, i)

Expand Down
Loading