Convert images to RGB before thumbnailing and writing as JPEG.

This commit is contained in:
Sybren A. Stüvel 2016-05-31 14:44:23 +02:00
parent c5985a3060
commit 8761dd1b91

View File

@ -29,7 +29,7 @@ def generate_local_thumbnails(name_base, src):
resize_and_crop(src, dst, settings['size']) resize_and_crop(src, dst, settings['size'])
width, height = settings['size'] width, height = settings['size']
else: else:
im = Image.open(src) im = Image.open(src).convert('RGB')
im.thumbnail(settings['size']) im.thumbnail(settings['size'])
im.save(dst, "JPEG") im.save(dst, "JPEG")
width, height = im.size width, height = im.size
@ -70,7 +70,7 @@ def resize_and_crop(img_path, modified_path, size, crop_type='middle'):
""" """
# If height is higher we resize vertically, if not we resize horizontally # If height is higher we resize vertically, if not we resize horizontally
img = Image.open(img_path) img = Image.open(img_path).convert('RGB')
# Get current and desired ratio for the images # Get current and desired ratio for the images
img_ratio = img.size[0] / float(img.size[1]) img_ratio = img.size[0] / float(img.size[1])
ratio = size[0] / float(size[1]) ratio = size[0] / float(size[1])