From 20a96e1e51badc9b77528915aca74c0656009cfe Mon Sep 17 00:00:00 2001 From: "a.gorbunov" Date: Mon, 20 Jan 2020 10:40:34 +0000 Subject: [PATCH] optimize news images --- apps/news/management/commands/news_optimize_images.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/news/management/commands/news_optimize_images.py b/apps/news/management/commands/news_optimize_images.py index 440afbc2..8b99c774 100644 --- a/apps/news/management/commands/news_optimize_images.py +++ b/apps/news/management/commands/news_optimize_images.py @@ -1,6 +1,7 @@ # coding=utf-8 from django.core.management.base import BaseCommand +from project.settings import SCHEMA_URI, SITE_DOMAIN_URI from utils.methods import get_url_images_in_text, get_image_meta_by_url from news.models import News from sorl.thumbnail import get_thumbnail @@ -29,6 +30,11 @@ class Command(BaseCommand): def optimize(self, text, max_size, max_quality): """optimize news images""" for image in get_url_images_in_text(text): + if not image.startswith('http'): + image = f'{SCHEMA_URI}://{SITE_DOMAIN_URI}{image}' + + self.stdout.write(self.style.NOTICE(f'{image}')) + try: size, width, height = get_image_meta_by_url(image) except IOError as ie: