diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d534d0269ea..e33f54ff5891 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,9 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Increased default guide assets limitations (30 assets, up to 10Mb each) + () - \[SDK\] Custom `ProgressReporter` implementations should now override `start2` instead of `start` () + ### Deprecated - TDB diff --git a/cvat/apps/engine/views.py b/cvat/apps/engine/views.py index a89ebb773a13..220502aaa505 100644 --- a/cvat/apps/engine/views.py +++ b/cvat/apps/engine/views.py @@ -6,6 +6,7 @@ import io import os import os.path as osp +from PIL import Image from types import SimpleNamespace from typing import Optional import pytz @@ -2720,9 +2721,16 @@ def create(self, request, *args, **kwargs): self.perform_create(serializer) path = os.path.join(settings.ASSETS_ROOT, str(serializer.instance.uuid)) os.makedirs(path) - with open(os.path.join(path, file.name), 'wb+') as destination: - for chunk in file.chunks(): - destination.write(chunk) + if file.content_type in ('image/jpeg', 'image/png'): + image = Image.open(file) + if any(map(lambda x: x > settings.ASSET_MAX_IMAGE_SIZE, image.size)): + scale_factor = settings.ASSET_MAX_IMAGE_SIZE / max(image.size) + image = image.resize((map(lambda x: int(x * scale_factor), image.size))) + image.save(os.path.join(path, file.name)) + else: + with open(os.path.join(path, file.name), 'wb+') as destination: + for chunk in file.chunks(): + destination.write(chunk) headers = self.get_success_headers(serializer.data) return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers) diff --git a/cvat/settings/base.py b/cvat/settings/base.py index 82b198d36426..69e2c7f33d0e 100644 --- a/cvat/settings/base.py +++ b/cvat/settings/base.py @@ -695,8 +695,9 @@ class CVAT_QUEUES(Enum): IMPORT_CACHE_SUCCESS_TTL = timedelta(hours=1) IMPORT_CACHE_CLEAN_DELAY = timedelta(hours=2) -ASSET_MAX_SIZE_MB = 2 +ASSET_MAX_SIZE_MB = 10 ASSET_SUPPORTED_TYPES = ('image/jpeg', 'image/png', 'image/webp', 'image/gif', 'application/pdf', ) -ASSET_MAX_COUNT_PER_GUIDE = 10 +ASSET_MAX_IMAGE_SIZE = 1920 +ASSET_MAX_COUNT_PER_GUIDE = 30 SMOKESCREEN_ENABLED = True