Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Workers
Base Worker
Commits
2d07cf35
Commit
2d07cf35
authored
1 year ago
by
Manon Blanco
Browse files
Options
Downloads
Patches
Plain Diff
Do not compute ratio
parent
521419cf
No related branches found
No related tags found
1 merge request
!395
Allow a worker to specify the needed size of the image
Pipeline
#131815
passed
1 year ago
Stage: test
Stage: build
Stage: release
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
arkindex_worker/cache.py
+1
-10
1 addition, 10 deletions
arkindex_worker/cache.py
arkindex_worker/models.py
+1
-8
1 addition, 8 deletions
arkindex_worker/models.py
tests/test_cache.py
+2
-2
2 additions, 2 deletions
tests/test_cache.py
tests/test_element.py
+3
-3
3 additions, 3 deletions
tests/test_element.py
with
7 additions
and
23 deletions
arkindex_worker/cache.py
+
1
−
10
View file @
2d07cf35
...
...
@@ -157,17 +157,8 @@ class CachedElement(Model):
max_height
is
None
or
self
.
image
.
height
<=
max_height
):
resize
=
"
full
"
elif
max_width
is
not
None
and
max_height
is
not
None
:
resize
=
f
"
{
max_width
}
,
{
max_height
}
"
else
:
ratio
=
max
(
(
max_width
or
0
)
/
self
.
image
.
width
,
(
max_height
or
0
)
/
self
.
image
.
height
,
)
new_width
,
new_height
=
int
(
self
.
image
.
width
*
ratio
),
int
(
self
.
image
.
height
*
ratio
)
resize
=
f
"
{
new_width
}
,
{
new_height
}
"
resize
=
f
"
{
max_width
or
''
}
,
{
max_height
or
''
}
"
url
=
self
.
image
.
url
if
not
url
.
endswith
(
"
/
"
):
...
...
This diff is collapsed.
Click to expand it.
arkindex_worker/models.py
+
1
−
8
View file @
2d07cf35
...
...
@@ -205,15 +205,8 @@ class Element(MagicDict):
):
resize
=
"
full
"
# Resizing if the image is bigger than the wanted size.
elif
max_width
is
not
None
and
max_height
is
not
None
:
resize
=
f
"
{
max_width
}
,
{
max_height
}
"
else
:
ratio
=
max
(
(
max_width
or
0
)
/
original_size
[
"
w
"
],
(
max_height
or
0
)
/
original_size
[
"
h
"
],
)
new_width
,
new_height
=
[
int
(
x
*
ratio
)
for
x
in
original_size
.
values
()]
resize
=
"
{},{}
"
.
format
(
new_width
,
new_height
)
resize
=
f
"
{
max_width
or
''
}
,
{
max_height
or
''
}
"
if
use_full_image
:
url
=
self
.
image_url
(
resize
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_cache.py
+
2
−
2
View file @
2d07cf35
...
...
@@ -240,7 +240,7 @@ def test_check_version_same_version(tmp_path):
600
,
None
,
400
,
"
http://something/full/
266
,400/0/default.jpg
"
,
"
http://something/full/,400/0/default.jpg
"
,
),
(
600
,
...
...
@@ -251,7 +251,7 @@ def test_check_version_same_version(tmp_path):
400
,
400
,
None
,
"
http://something/full/400,
266
/0/default.jpg
"
,
"
http://something/full/400,/0/default.jpg
"
,
),
(
400
,
...
...
This diff is collapsed.
Click to expand it.
tests/test_element.py
+
3
−
3
View file @
2d07cf35
...
...
@@ -105,7 +105,7 @@ def test_open_image_resize_portrait(mocker):
assert
elt
.
open_image
(
max_height
=
400
,
use_full_image
=
True
)
==
"
an image!
"
assert
open_mock
.
call_count
==
2
assert
open_mock
.
call_args
==
mocker
.
call
(
"
http://something/full/
266
,400/0/default.jpg
"
,
"
http://something/full/,400/0/default.jpg
"
,
rotation_angle
=
0
,
mirrored
=
False
,
)
...
...
@@ -178,7 +178,7 @@ def test_open_image_resize_landscape(mocker):
assert
elt
.
open_image
(
max_width
=
400
,
use_full_image
=
True
)
==
"
an image!
"
assert
open_mock
.
call_count
==
2
assert
open_mock
.
call_args
==
mocker
.
call
(
"
http://something/full/400,
266
/0/default.jpg
"
,
"
http://something/full/400,/0/default.jpg
"
,
rotation_angle
=
0
,
mirrored
=
False
,
)
...
...
@@ -388,7 +388,7 @@ def test_open_image_resize_use_full_image_false(mocker):
assert
elt
.
open_image
(
max_height
=
200
,
use_full_image
=
False
)
==
"
an image!
"
assert
open_mock
.
call_count
==
1
assert
open_mock
.
call_args
==
mocker
.
call
(
"
http://zoneurl/0,0,400,600/
133
,200/0/default.jpg
"
,
"
http://zoneurl/0,0,400,600/,200/0/default.jpg
"
,
rotation_angle
=
0
,
mirrored
=
False
,
)
...
...
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