optimize news images
This commit is contained in:
parent
bb8accefbf
commit
20a96e1e51
|
|
@ -1,6 +1,7 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from django.core.management.base import BaseCommand
|
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 utils.methods import get_url_images_in_text, get_image_meta_by_url
|
||||||
from news.models import News
|
from news.models import News
|
||||||
from sorl.thumbnail import get_thumbnail
|
from sorl.thumbnail import get_thumbnail
|
||||||
|
|
@ -29,6 +30,11 @@ class Command(BaseCommand):
|
||||||
def optimize(self, text, max_size, max_quality):
|
def optimize(self, text, max_size, max_quality):
|
||||||
"""optimize news images"""
|
"""optimize news images"""
|
||||||
for image in get_url_images_in_text(text):
|
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:
|
try:
|
||||||
size, width, height = get_image_meta_by_url(image)
|
size, width, height = get_image_meta_by_url(image)
|
||||||
except IOError as ie:
|
except IOError as ie:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user