Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
f2f9d08a
Commit
f2f9d08a
authored
3 years ago
by
Erwan Rouchet
Committed by
Bastien Abadie
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add rotation and mirroring to IIIF thumbnail URLs
parent
51d2cf28
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1550
Add rotation and mirroring to IIIF thumbnail URLs
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/documents/models.py
+15
-4
15 additions, 4 deletions
arkindex/documents/models.py
arkindex/documents/tests/test_element.py
+70
-0
70 additions, 0 deletions
arkindex/documents/tests/test_element.py
with
85 additions
and
4 deletions
arkindex/documents/models.py
+
15
−
4
View file @
f2f9d08a
...
...
@@ -370,11 +370,22 @@ class Element(IndexableModel):
@property
def
iiif_thumbnail_url
(
self
):
"""
Same as `iiif_url`, but resized to up to 400 pixels
Same as `iiif_url`, but resized to up to 400 pixels
and with rotation and mirroring
"""
iiif_url
=
self
.
iiif_url
if
iiif_url
:
return
self
.
iiif_url
.
replace
(
'
full
'
,
'
,400
'
)
if
not
self
.
polygon
or
not
self
.
image_id
:
return
from
arkindex.project.tools
import
bounding_box
x
,
y
,
width
,
height
=
bounding_box
(
self
.
polygon
)
rotation_param
=
str
(
self
.
rotation_angle
)
if
self
.
mirrored
:
rotation_param
=
f
'
!
{
rotation_param
}
'
return
urljoin
(
self
.
image
.
url
+
'
/
'
,
f
'
{
x
}
,
{
y
}
,
{
width
}
,
{
height
}
/,400/
{
rotation_param
}
/default.jpg
'
)
def
__str__
(
self
):
return
'
{}: {}
'
.
format
(
self
.
type
.
display_name
,
self
.
name
)
...
...
This diff is collapsed.
Click to expand it.
arkindex/documents/tests/test_element.py
0 → 100644
+
70
−
0
View file @
f2f9d08a
from
arkindex.documents.models
import
Element
from
arkindex.project.tests
import
FixtureTestCase
class
TestElement
(
FixtureTestCase
):
@classmethod
def
setUpTestData
(
cls
):
super
().
setUpTestData
()
cls
.
element_type
=
cls
.
corpus
.
types
.
first
()
cls
.
image
=
cls
.
imgsrv
.
images
.
get
(
path
=
'
img1
'
)
def
test_iiif_url
(
self
):
# Rotation and mirroring should be ignored in iiif_url
cases
=
[
(
0
,
False
),
(
0
,
True
),
(
180
,
False
),
(
180
,
True
),
]
for
rotation_angle
,
mirrored
in
cases
:
with
self
.
subTest
(
rotation_angle
=
rotation_angle
,
mirrored
=
mirrored
):
element
=
Element
(
name
=
'
Something
'
,
type
=
self
.
element_type
,
image
=
self
.
image
,
polygon
=
[
[
10
,
20
],
[
40
,
20
],
[
40
,
60
],
[
10
,
60
],
[
10
,
20
],
],
rotation_angle
=
rotation_angle
,
mirrored
=
mirrored
,
)
self
.
assertEqual
(
element
.
iiif_url
,
'
http://server/img1/10,20,30,40/full/0/default.jpg
'
)
def
test_iiif_thumbnail_url
(
self
):
cases
=
[
(
0
,
False
,
'
http://server/img1/10,20,30,40/,400/0/default.jpg
'
),
(
0
,
True
,
'
http://server/img1/10,20,30,40/,400/!0/default.jpg
'
),
(
180
,
False
,
'
http://server/img1/10,20,30,40/,400/180/default.jpg
'
),
(
180
,
True
,
'
http://server/img1/10,20,30,40/,400/!180/default.jpg
'
),
]
for
rotation_angle
,
mirrored
,
expected_url
in
cases
:
with
self
.
subTest
(
rotation_angle
=
rotation_angle
,
mirrored
=
mirrored
):
element
=
Element
(
name
=
'
Something
'
,
type
=
self
.
element_type
,
image
=
self
.
image
,
polygon
=
[
[
10
,
20
],
[
40
,
20
],
[
40
,
60
],
[
10
,
60
],
[
10
,
20
],
],
rotation_angle
=
rotation_angle
,
mirrored
=
mirrored
,
)
self
.
assertEqual
(
element
.
iiif_thumbnail_url
,
expected_url
)
def
test_no_image_no_url
(
self
):
element
=
Element
(
name
=
'
Something
'
,
type
=
self
.
element_type
,
)
self
.
assertIsNone
(
element
.
iiif_url
)
self
.
assertIsNone
(
element
.
iiif_thumbnail_url
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment