Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
zesje
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
7
Issues
7
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Works on my machine
zesje
Commits
9f3409f8
Commit
9f3409f8
authored
Jun 10, 2019
by
Hugo Kerstens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add dimension check to image extraction
parent
5dcde227
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
2 deletions
+18
-2
zesje/scans.py
zesje/scans.py
+18
-2
No files found.
zesje/scans.py
View file @
9f3409f8
...
...
@@ -183,7 +183,11 @@ def extract_image_pikepdf(pagenr, reader):
Raises
------
ValueError if not exactly one image is found on the page
ValueError
if not exactly one image is found on the page or the
image does not have the same dimensions as the page
AttributeError
if no XObject or MediaBox is present on the page
"""
page
=
reader
.
pages
[
pagenr
]
...
...
@@ -192,11 +196,23 @@ def extract_image_pikepdf(pagenr, reader):
if
sum
((
xObject
[
obj
]
.
Subtype
==
'/Image'
)
for
obj
in
xObject
)
!=
1
:
raise
ValueError
raise
ValueError
(
'Not exactly 1 image present on the page'
)
for
obj
in
xObject
:
if
xObject
[
obj
]
.
Subtype
==
'/Image'
:
pdfimage
=
PdfImage
(
xObject
[
obj
])
pdf_width
=
float
(
page
.
MediaBox
[
2
]
-
page
.
MediaBox
[
0
])
pdf_height
=
float
(
page
.
MediaBox
[
3
]
-
page
.
MediaBox
[
1
])
ratio_width
=
pdfimage
.
width
/
pdf_width
ratio_height
=
pdfimage
.
height
/
pdf_height
# Check if the dimensions of the image are the same as the
# dimensions of the page up to a 3% relative error
if
abs
(
ratio_width
-
ratio_height
)
>
0.03
*
ratio_width
:
raise
ValueError
(
'Image has incorrect dimensions'
)
return
pdfimage
.
as_pil_image
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment