Skip to content

Commit

Permalink
Add test files and require Pillow 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
saimn committed Feb 7, 2021
1 parent 8f5c633 commit 99a1809
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 20 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ install_requires =
click
Jinja2
Markdown
Pillow>=4.0.0
Pillow>=6.0.0
pilkit
natsort

Expand Down
24 changes: 6 additions & 18 deletions sigal/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,14 @@
from PIL import Image as PILImage
from PIL import ImageFile, ImageOps, IptcImagePlugin
from PIL.ExifTags import GPSTAGS, TAGS
from PIL.Image import Exif

import pilkit.processors
from pilkit.processors import Transpose
from pilkit.utils import save_image

try:
# Pillow 6.0 added a class allowing to write Exif data
from PIL.Image import Exif
except ImportError:
Exif = None

from . import signals, utils
from .settings import Status, get_thumb
from .settings import Status

try:
# Pillow 7.2+
Expand All @@ -79,8 +74,8 @@ def _read_image(file_path):
im = PILImage.open(file_path)

for w in caught_warnings:
logger.warning(f'PILImage reported a warning for file {file_path}\n'
f'{w.category}: {w.message}')
logger.info(f'PILImage reported a warning for file {file_path}\n'
f'{w.category}: {w.message}')
return im


Expand Down Expand Up @@ -124,15 +119,8 @@ def generate_image(source, outname, settings, options=None):
pass
else:
if copy_exif and 'exif' in options:
if Exif is not None:
# reset the orientation flag
options['exif'][0x0112] = 1
else:
logger.warning(
"'autorotate_images' and 'copy_exif_data' settings "
"are not compatible when using Pillow < 6.0, because "
"Sigal can't save the modified Orientation tag."
)
# reset the orientation flag
options['exif'][0x0112] = 1

# Resize the image
if settings['img_processor']:
Expand Down
Binary file added tests/sample/pictures/exifTest/lamas.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/sample/sigal.conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
keep_orig = True
thumb_video_delay = 5
# img_format = 'jpeg'
copy_exif_data = True

links = [('Example link', 'http://example.org'),
('Another link', 'http://example.org')]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_extended_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_save_cache(settings, tmpdir):

assert cache["exifTest/21.jpg"] == gal.albums["exifTest"].medias[0].exif
assert cache["exifTest/22.jpg"] == gal.albums["exifTest"].medias[1].exif
assert cache["exifTest/noexif.png"] == gal.albums["exifTest"].medias[2].exif
assert cache["exifTest/noexif.png"] is None


def test_restore_cache(settings, tmpdir):
Expand Down

0 comments on commit 99a1809

Please sign in to comment.