Browse Source

add thumbnail generator customizado

assim como a os broswer para rendenderizar a tag <img> desconsideram a
informação de EXIF.orientation, um thumbnail_generator customizado é
necessário para manter a comportamento... para haver reflexo, as imagens
secundárias devem ser apagadas de MEDIA_ROOT, não sendo necessário pois,
reenviar as imagens primárias.
pull/1728/head
LeandroRoberto 7 years ago
parent
commit
345da6ddcc
  1. 3
      sapl/settings.py
  2. 17
      sapl/utils.py

3
sapl/settings.py

@ -188,6 +188,9 @@ THUMBNAIL_PROCESSORS = (
'image_cropping.thumbnail_processors.crop_corners', 'image_cropping.thumbnail_processors.crop_corners',
) + thumbnail_settings.THUMBNAIL_PROCESSORS ) + thumbnail_settings.THUMBNAIL_PROCESSORS
THUMBNAIL_SOURCE_GENERATORS = (
'sapl.utils.pil_image',
)
# troque no caso de reimplementação da classe User conforme # troque no caso de reimplementação da classe User conforme
# https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#substituting-a-custom-user-model # https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#substituting-a-custom-user-model

17
sapl/utils.py

@ -1,13 +1,11 @@
from functools import wraps
from operator import itemgetter
from unicodedata import normalize as unicodedata_normalize
import hashlib import hashlib
import logging import logging
import os import os
import re import re
from functools import wraps
from operator import itemgetter
from unicodedata import normalize as unicodedata_normalize
import django_filters
import magic
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button from crispy_forms.layout import HTML, Button
from django import forms from django import forms
@ -21,14 +19,23 @@ from django.db.models import Q
from django.utils import six, timezone from django.utils import six, timezone
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django_filters.filterset import STRICTNESS from django_filters.filterset import STRICTNESS
from easy_thumbnails import source_generators
from floppyforms import ClearableFileInput from floppyforms import ClearableFileInput
from reversion.admin import VersionAdmin from reversion.admin import VersionAdmin
import django_filters
import magic
from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row
from sapl.settings import BASE_DIR from sapl.settings import BASE_DIR
sapl_logger = logging.getLogger(BASE_DIR.name) sapl_logger = logging.getLogger(BASE_DIR.name)
def pil_image(source, exif_orientation=False, **options):
return source_generators.pil_image(source, exif_orientation, **options)
def normalize(txt): def normalize(txt):
return unicodedata_normalize( return unicodedata_normalize(
'NFKD', txt).encode('ASCII', 'ignore').decode('ASCII') 'NFKD', txt).encode('ASCII', 'ignore').decode('ASCII')

Loading…
Cancel
Save