Fixed thumbnail generation
rodzic
4d8198edbf
commit
b8fe41f551
|
@ -15,17 +15,14 @@ THUMBNAIL_SIZES = {
|
|||
|
||||
|
||||
@shared_task
|
||||
def generate_thumbnails(image_url):
|
||||
def generate_thumbnails(image_path):
|
||||
try:
|
||||
thumbnailer = get_thumbnailer(image_path)
|
||||
thumbnails = {}
|
||||
thumbnailer = get_thumbnailer(image_url)
|
||||
|
||||
for size_name, (width, height, crop) in THUMBNAIL_SIZES.items():
|
||||
thumbnail = thumbnailer.get_thumbnail({'size': (width, height), 'crop': crop})
|
||||
thumbnail_url = thumbnail.url
|
||||
thumbnails[size_name] = thumbnail_url
|
||||
|
||||
thumbnails[size_name] = thumbnail.url
|
||||
return thumbnails
|
||||
except Exception as e:
|
||||
logger.exception(f"Error generating thumbnails for image_instance {image_url}: {e}")
|
||||
logger.exception(f"Error generating thumbnails for image_instance {image_path}: {e}")
|
||||
return None
|
||||
|
|
|
@ -75,6 +75,7 @@ services:
|
|||
command: celery -A artel worker -l info
|
||||
volumes:
|
||||
- ./:/app
|
||||
- media:/app/media
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
|
|
|
@ -5,6 +5,6 @@ from artel.tasks import generate_thumbnails
|
|||
|
||||
|
||||
@receiver(post_save, sender=ProductTemplateImage)
|
||||
def create_thumbnail_on_image_creation(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
generate_thumbnails.delay(instance.image.url)
|
||||
def generate_thumbnail(sender, instance, **kwargs):
|
||||
image_path = instance.image.path
|
||||
generate_thumbnails.delay(image_path)
|
||||
|
|
Ładowanie…
Reference in New Issue