Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1942 - Modifies the Image saving parameters for better quality #2566

Merged
merged 4 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GitHub-Flask==3.1.5
mock==2.0.0
nose==1.3.7
pep8==1.7.0
Pillow==4.0.0
Pillow==5.2.0
requests==2.13.0
ua-parser==0.8
WTForms==2.1
7 changes: 5 additions & 2 deletions webcompat/api/uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ def save(self):
dest_dir = os.path.dirname(file_dest)
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
# Alpha channels are not supported in JPEG
if (self.image_object.format == 'PNG'):
self.image_object = self.image_object.convert('RGB')
# Optimize further the image compression for these formats
if self.image_object.format in ['JPEG', 'JPG', 'JPE', 'PNG']:
save_parameters['optimize'] = True
Expand All @@ -116,8 +119,8 @@ def save(self):
# unpacking save_parameters
self.image_object.save(file_dest, **save_parameters)
# Creating the thumbnail
size = (700, 700)
self.image_object.thumbnail(size, Image.BILINEAR)
size = (1024, 1024)
self.image_object.thumbnail(size, Image.HAMMING)
self.image_object.save(thumb_dest, **save_parameters)


Expand Down