refactor: Move image processing configuration to settings

Refactored image processing system to use centralized configuration in settings.IMAGE_PROCESSING_CONFIG instead of hardcoded values.

Changes:
- Added IMAGE_PROCESSING_CONFIG to settings with configurable sizes, formats, and quality
- Rewrote ImageProcessor to use dynamic configuration from settings
- Added support for multiple image formats (JPEG, WebP, PNG)
- Updated _save_image_version() to handle different formats and quality levels
- Added original image scaling (max 2160×2160) and square aspect ratio
- Updated ImageService to work with different file extensions (.jpg, .webp, .png)
- All parameters now easily configurable without code changes

Configuration:
- Original: JPEG, quality 100, max 2160×2160 (always square)
- Large: WebP, quality 90, 1200×1200
- Medium: WebP, quality 85, 600×600
- Thumbnail: WebP, quality 80, 200×200

Benefits:
- Flexible and maintainable configuration
- Smaller file sizes (WebP for resized images)
- Maximum quality for originals (JPEG 100)
- Square aspect ratio for better consistency

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-22 23:34:14 +03:00
parent a9b16bf212
commit f12fd18190
4 changed files with 529 additions and 62 deletions

View File

@@ -127,6 +127,51 @@ STATIC_ROOT = BASE_DIR / 'staticfiles' # Для collectstatic
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'
# ============================================
# IMAGE PROCESSING SETTINGS
# ============================================
# Конфигурация для обработки изображений товаров, комплектов и категорий
# Определяет размеры, форматы и качество для каждого типа изображения
IMAGE_PROCESSING_CONFIG = {
'formats': {
'original': {
'format': 'JPEG',
'quality': 100,
'max_width': 2160,
'max_height': 2160,
'description': 'Original image (4K max, JPEG format)'
},
'large': {
'format': 'WEBP',
'quality': 90,
'width': 1200,
'height': 1200,
'description': 'Large image (1200x1200, WebP format)'
},
'medium': {
'format': 'WEBP',
'quality': 85,
'width': 600,
'height': 600,
'description': 'Medium image (600x600, WebP format)'
},
'thumbnail': {
'format': 'WEBP',
'quality': 80,
'width': 200,
'height': 200,
'description': 'Thumbnail (200x200, WebP format)'
},
},
'folders': {
'original': 'originals',
'large': 'large',
'medium': 'medium',
'thumbnail': 'thumbnails',
}
}
# Настройки категорий товаров
# Максимальная глубина вложенности категорий (защита от слишком глубокой иерархии)
MAX_CATEGORY_DEPTH = 10