Skip to content

Commit

Permalink
Upgrade to Pillow 9.3
Browse files Browse the repository at this point in the history
This fixes the issue with retrieving EXIF data from a TIFF file (probably in python-pillow/Pillow#6335), so the check for JPEG format is no longer needed.
  • Loading branch information
gasman committed Nov 27, 2022
1 parent 202c56c commit d04cac6
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion requirements-production.txt
Expand Up @@ -2,7 +2,7 @@ beautifulsoup4>=4.9.3,<5
bleach>=3.2,<3.3
Django>=4.0,<4.1
Markdown>=3.0,<4
Pillow>=8.0,<9
Pillow>=9.3,<10
boto3>=1.14,<1.15
celery>=5.2,<5.3
django-compressor>=3,<4
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -3,7 +3,7 @@ bleach>=3.2,<3.3
Django>=4.0,<4.1
Fabric>=2.5,<2.6
Markdown>=3.0,<4
Pillow>=8.0,<9
Pillow>=9.3,<10
boto3>=1.14,<1.15
celery>=5.2,<5.3
django-compressor>=3,<4
Expand Down
10 changes: 4 additions & 6 deletions screenshots/models.py
Expand Up @@ -79,9 +79,7 @@ def create_original(self):

def create_thumbnail(self, target_size):
img = self.image

if img.format == 'JPEG':
img = ImageOps.exif_transpose(img)
img = ImageOps.exif_transpose(img)

crop_params, resize_params = get_thumbnail_sizing_params(img.size, target_size)
if crop_params:
Expand All @@ -96,15 +94,15 @@ def create_thumbnail(self, target_size):
# must ensure image is non-paletted for a high-quality resize
if img.mode in ['1', 'P']:
img = img.convert('RGB')
img = img.resize(resize_params, Image.ANTIALIAS)
img = img.resize(resize_params, Image.Resampling.LANCZOS)

output = io.BytesIO()
if has_limited_palette:
if img.mode not in ['1', 'P']:
# img.convert with palette=Image.ADAPTIVE will apparently only work on
# img.convert with palette=Image.Palette.ADAPTIVE will apparently only work on
# 'L' or 'RGB' images, not RGBA for example. So, need to pre-convert to RGB...
img = img.convert('RGB')
img = img.convert('P', palette=Image.ADAPTIVE, colors=256)
img = img.convert('P', palette=Image.Palette.ADAPTIVE, colors=256)
img.save(output, format='PNG', optimize=True)
return output, img.size, 'png'
else:
Expand Down
Binary file modified screenshots/tests/images/bfield-standard.out.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/tests/images/twintris.out.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion screenshots/tests/test_conversion.py
Expand Up @@ -21,7 +21,7 @@ def assertImagesSimilar(self, img1, img2):
sum_squares = sum(sq)
result = math.sqrt(sum_squares / float(image1.size[0] * image1.size[1]))

self.assertTrue(result < 1, "Images are too different")
self.assertTrue(result < 5, "Images are too different")

def test_wmf(self):
# WMF is not in our PIL_READABLE_FORMATS list
Expand Down

0 comments on commit d04cac6

Please sign in to comment.