Merge branch 'bug/optimize-collection-images' into 'develop'
optimize news images See merge request gm/gm-backend!223
This commit is contained in:
commit
914c8fc9f3
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user