Skip to content

Commit cadac75

Browse files
github-actions[bot]github-actionsaurelienlombardAurélien LombardRuellePaul
authored
chore: merge release/2.169.1 into main (#1870)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions <[email protected]> Co-authored-by: aurelienlombard <[email protected]> Co-authored-by: Aurélien Lombard <[email protected]> Co-authored-by: Ruelle Paul <[email protected]> Co-authored-by: paulruelle <[email protected]> Co-authored-by: florianlega <[email protected]> Co-authored-by: Clément Bussière <[email protected]>
1 parent 6658436 commit cadac75

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["setuptools", "wheel"]
33

44
[project]
55
name = "kili"
6-
version = "2.169.0"
6+
version = "2.169.1"
77
description = "Python client for Kili Technology labeling tool"
88
readme = "README.md"
99
authors = [{ name = "Kili Technology", email = "[email protected]" }]

src/kili/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Kili Python SDK."""
22

3-
__version__ = "2.169.0"
3+
__version__ = "2.169.1"

src/kili/services/asset_import/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99

1010
MB_SIZE = 1024**2
1111
LARGE_IMAGE_THRESHOLD_SIZE = 30 * MB_SIZE
12+
MAX_WIDTH_OR_HEIGHT_NON_TILED = 10000

src/kili/services/asset_import/image.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
import os
44
from typing import List
55

6+
from PIL import Image, UnidentifiedImageError
7+
68
from kili.core.constants import mime_extensions_that_need_post_processing
79
from kili.core.helpers import get_mime_type
810
from kili.domain.project import InputType
911

1012
from .base import BaseAbstractAssetImporter, BatchParams, ContentBatchImporter
11-
from .constants import LARGE_IMAGE_THRESHOLD_SIZE
13+
from .constants import LARGE_IMAGE_THRESHOLD_SIZE, MAX_WIDTH_OR_HEIGHT_NON_TILED
1214
from .types import AssetLike
1315

16+
Image.MAX_IMAGE_PIXELS = None
17+
1418

1519
class ImageDataImporter(BaseAbstractAssetImporter):
1620
"""Class for importing assets into an IMAGE or GEOSPATIAL project."""
@@ -46,6 +50,16 @@ def import_assets(self, assets: List[AssetLike], input_type: InputType):
4650
)
4751
return created_asset_ids
4852

53+
@staticmethod
54+
def get_is_large_image(image_path: str) -> bool:
55+
"""Define if an image is too large and so on has to be tiled."""
56+
if os.path.getsize(image_path) >= LARGE_IMAGE_THRESHOLD_SIZE:
57+
return True
58+
59+
image = Image.open(image_path)
60+
width, height = image.size
61+
return width >= MAX_WIDTH_OR_HEIGHT_NON_TILED or height >= MAX_WIDTH_OR_HEIGHT_NON_TILED
62+
4963
@staticmethod
5064
def split_asset_by_upload_type(assets: List[AssetLike], is_hosted: bool):
5165
"""Split assets into two groups, assets to to imported synchronously or asynchronously."""
@@ -65,9 +79,15 @@ def split_asset_by_upload_type(assets: List[AssetLike], is_hosted: bool):
6579
assert path
6680
assert isinstance(path, str)
6781
mime_type = get_mime_type(path)
68-
is_large_image = os.path.getsize(path) >= LARGE_IMAGE_THRESHOLD_SIZE
69-
if is_large_image or mime_type in mime_extensions_that_need_post_processing:
82+
if mime_type in mime_extensions_that_need_post_processing:
7083
async_assets.append(asset)
7184
else:
72-
sync_assets.append(asset)
85+
try:
86+
is_large_image = ImageDataImporter.get_is_large_image(path)
87+
if is_large_image:
88+
async_assets.append(asset)
89+
else:
90+
sync_assets.append(asset)
91+
except UnidentifiedImageError:
92+
async_assets.append(asset)
7393
return sync_assets, async_assets

0 commit comments

Comments
 (0)