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

Bug in mediabox expansion when applying non-right angle rotation #2282

Merged
merged 6 commits into from
Nov 14, 2023

Conversation

MrinalJain17
Copy link
Contributor

Fixes #2281

@pubpub-zz
Copy link
Collaborator

@MrinalJain17, can you confirm that when applying angle from -370 to +360, all results are as expected ?

@MrinalJain17
Copy link
Contributor Author

Yes @pubpub-zz

In fact, given below is a comparison of the dimensions of a page after it has been rotated with pypdf vs pillow. With expansion enabled in both scenarios.

I've also manually checked the results of course.

Current (before fix):

image

New (after fix):

278074508-ea25073a-d536-489e-9e39-bfa29578adc6-2

@pubpub-zz
Copy link
Collaborator

your results are very good! can you add a test in order to make sure that the issue will not come back ?

with open(expected_pdf_path, "rb") as f:
expected_pdf_bytes = BytesIO(f.read())

assert rotated_pdf_bytes.getvalue() == expected_pdf_bytes.getvalue()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have just look at the box size as you did in your graphs with a criteria <1E-4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense @pubpub-zz . I've updated the tests.

Due to rounding/interpolation, there's deviation of about 1-ish pixels compared to pillow. I've set an absolute tolerance of 2 pixels instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lmk if this looks good. Or if you want me to set the expected dimensions to be what pypdf actually ends up with -- and compare with a small tolerance instead.

@MrinalJain17
Copy link
Contributor Author

Hi @pubpub-zz. Checking in on this -- lmk if there's anything else needed.

@pubpub-zz
Copy link
Collaborator

This looks good to me👏
@MartinThoma all yours😉

tests/test_page.py Outdated Show resolved Hide resolved
tests/test_page.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Nov 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (e11c2b6) 94.45% compared to head (405aa2f) 94.45%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2282      +/-   ##
==========================================
- Coverage   94.45%   94.45%   -0.01%     
==========================================
  Files          43       43              
  Lines        7651     7649       -2     
  Branches     1511     1511              
==========================================
- Hits         7227     7225       -2     
  Misses        262      262              
  Partials      162      162              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MartinThoma MartinThoma merged commit 03bce94 into py-pdf:main Nov 14, 2023
14 checks passed
@MartinThoma
Copy link
Member

@MrinalJain17 Thank you for this fix and the explanation around it in the PR 🙏

If you want, I can add you to https://pypdf.readthedocs.io/en/latest/meta/CONTRIBUTORS.html :-)

MartinThoma added a commit that referenced this pull request Nov 14, 2023
## What's new

### Bug Fixes (BUG)
-  Mediabox expansion size when applying non-right angle rotation (#2282) by @MrinalJain17

### Robustness (ROB)
-  MissingWidth is IndirectObject (#2288) by @MartinThoma
-  Initialize states array with an empty value (#2280) by @alexey-v-paramonov

### Documentation (DOC)
-  Typo in example in extract-attachments.md (#2285) by @ageitgey
-  Add Alexey Paramonov as a contributor for #2280 by @MartinThoma

### Maintenance (MAINT)
-  Update sample-files by @MartinThoma

[Full Changelog](3.17.0...3.17.1)
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

Successfully merging this pull request may close these issues.

Bug in mediabox expansion when applying non-right angle rotation
3 participants