Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
DAN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Automatic Text Recognition
DAN
Merge requests
!279
Fix resizing
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Fix resizing
fix-resize
into
main
Overview
1
Commits
1
Pipelines
0
Changes
2
Merged
Yoann Schneider
requested to merge
fix-resize
into
main
1 year ago
Overview
1
Commits
1
Pipelines
0
Changes
2
Expand
Closes
#192 (closed)
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
e5ef0373
1 commit,
1 year ago
2 files
+
33
−
13
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
dan/datasets/extract/extract.py
+
14
−
12
Options
@@ -6,7 +6,6 @@ import pickle
import
random
from
collections
import
defaultdict
from
concurrent.futures
import
Future
,
ThreadPoolExecutor
from
functools
import
cached_property
from
pathlib
import
Path
from
typing
import
Dict
,
List
,
Optional
,
Union
from
uuid
import
UUID
@@ -91,23 +90,26 @@ class ArkindexExtractor:
# Image download tasks to process
self
.
tasks
:
List
[
Dict
[
str
,
str
]]
=
[]
@cached_property
def
max_resize
(
self
):
# We keep the aspect ratio so we only use on dimension, the biggest one
if
self
.
max_width
>
self
.
max_height
:
return
f
"
{
self
.
max_width
}
,
"
return
f
"
,
{
self
.
max_height
}
"
def
get_iiif_size_arg
(
self
,
width
:
int
,
height
:
int
)
->
str
:
if
(
self
.
max_width
is
None
or
width
<=
self
.
max_width
)
and
(
self
.
max_height
is
None
or
height
<=
self
.
max_height
):
return
IIIF_FULL_SIZE
# Resizing if the image is bigger than the wanted size.
if
self
.
max_width
and
self
.
max_height
:
return
self
.
max_resize
return
f
"
{
self
.
max_width
or
''
}
,
{
self
.
max_height
or
''
}
"
bigger_width
=
self
.
max_width
and
width
>=
self
.
max_width
bigger_height
=
self
.
max_height
and
height
>=
self
.
max_height
if
bigger_width
and
bigger_height
:
# Resize to the biggest dim to keep aspect ratio
# Only resize width is bigger than max size
# This ratio tells which dim needs the biggest shrinking
ratio
=
width
*
self
.
max_height
/
(
height
*
self
.
max_width
)
return
f
"
{
self
.
max_width
}
,
"
if
ratio
>
1
else
f
"
,
{
self
.
max_height
}
"
elif
bigger_width
:
return
f
"
{
self
.
max_width
}
,
"
# Only resize height is bigger than max size
elif
bigger_height
:
return
f
"
,
{
self
.
max_height
}
"
def
build_iiif_url
(
self
,
polygon
,
image_url
):
bbox
=
polygon_to_bbox
(
json
.
loads
(
str
(
polygon
)))
Loading