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

Skipping Images During Processing in output_images Function #210

Open
adamcvolz opened this issue Dec 13, 2024 · 1 comment
Open

Skipping Images During Processing in output_images Function #210

adamcvolz opened this issue Dec 13, 2024 · 1 comment

Comments

@adamcvolz
Copy link

In the output_images function, if multiple images exist on a single page in the PDF, some images are skipped entirely due to a logic issue.

image

Cause:
The issue occurs because the code deletes a value at the index from the img_rects list during forward iteration. This deletion shrinks the list, causing the iteration to skip over subsequent elements that haven't yet been processed.

Example:
For example, if img_rects initially contains:
parms.img_rects = [image1, image2, image3]

When image1 is processed and deleted, the list becomes:
parms.img_rects = [image2, image3]

The next iteration starts at index 1, skipping image2 entirely.

Proposed Fix:
Iterate Backwards - Modify the loop to iterate backward over the list, which ensures that deleting an element doesn’t affect the indices of unprocessed elements:

for i in range(len(parms.img_rects) - 1, -1, -1):
    img_rect = parms.img_rects[i]
    # Process image...
    del parms.img_rects[i]

Seemed to solve the issue for me, however images were then in backwards order so I had to reverse the list.

@adamcvolz
Copy link
Author

Saw this issue was already reported - had missed it when looking. Did verify this is working as expected in the previous version 0.0.16, as well as the issue of image location being wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant