Skip to content

Commit b4d25cb

Browse files
committed
image quality settings test
1 parent 5e35863 commit b4d25cb

File tree

2 files changed

+67
-9
lines changed

2 files changed

+67
-9
lines changed

superannotate/db/projects.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,16 @@ def get_image_array_to_upload(
588588
byte_io_orig = io.BytesIO()
589589
im.save(byte_io_orig, im_format, subsampling=0, quality=100)
590590

591-
byte_io_lores = io.BytesIO()
592-
im.save(
593-
byte_io_lores,
594-
'JPEG',
595-
subsampling=0 if image_quality_in_editor > 60 else 2,
596-
quality=image_quality_in_editor
597-
)
591+
if not image_quality_in_editor == 100 or im_format != "JPEG":
592+
byte_io_lores = io.BytesIO()
593+
im.save(
594+
byte_io_lores,
595+
'JPEG',
596+
subsampling=0 if image_quality_in_editor > 60 else 2,
597+
quality=image_quality_in_editor
598+
)
599+
else:
600+
byte_io_lores = io.BytesIO(byte_io_orig.getbuffer())
598601

599602
byte_io_huge = io.BytesIO()
600603
hsize = int(height * 600.0 / width)
@@ -1646,10 +1649,10 @@ def _get_project_image_quality_in_editor(project, image_quality_in_editor):
16461649

16471650
def _set_project_default_image_quality_in_editor(project, quality):
16481651
set_project_settings(
1649-
project, {
1652+
project, [{
16501653
"attribute": "ImageQuality",
16511654
"value": quality
1652-
}
1655+
}]
16531656
)
16541657

16551658

tests/test_image_quality.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from pathlib import Path
2+
import filecmp
3+
4+
import superannotate as sa
5+
6+
import pytest
7+
8+
PROJECT_NAME1 = "test image qual setting1"
9+
PROJECT_NAME2 = "test image qual setting2"
10+
11+
12+
def test_image_quality_setting1(tmpdir):
13+
tmpdir = Path(tmpdir)
14+
15+
projects = sa.search_projects(PROJECT_NAME1, return_metadata=True)
16+
for project in projects:
17+
sa.delete_project(project)
18+
19+
project = sa.create_project(PROJECT_NAME1, "test", "Vector")
20+
21+
sa.upload_images_from_folder_to_project(
22+
project, "./tests/sample_project_vector"
23+
)
24+
25+
sa.download_image(project, "example_image_1.jpg", tmpdir, variant="lores")
26+
27+
assert not filecmp.cmp(
28+
tmpdir / "example_image_1.jpg___lores.jpg",
29+
"./tests/sample_project_vector/example_image_1.jpg",
30+
shallow=False
31+
)
32+
33+
34+
def test_image_quality_setting2(tmpdir):
35+
tmpdir = Path(tmpdir)
36+
37+
projects = sa.search_projects(PROJECT_NAME2, return_metadata=True)
38+
for project in projects:
39+
sa.delete_project(project)
40+
41+
project = sa.create_project(PROJECT_NAME2, "test", "Vector")
42+
43+
sa.set_project_default_image_quality_in_editor(project, "original")
44+
45+
sa.upload_images_from_folder_to_project(
46+
project, "./tests/sample_project_vector"
47+
)
48+
49+
sa.download_image(project, "example_image_1.jpg", tmpdir, variant="lores")
50+
51+
assert filecmp.cmp(
52+
tmpdir / "example_image_1.jpg___lores.jpg",
53+
"./tests/sample_project_vector/example_image_1.jpg",
54+
shallow=False
55+
)

0 commit comments

Comments
 (0)