Improvements to image thumbnailing
- Optimize JPEGs and increase quality from 75 to 95 - Don't always convert to RGB, first check if RGBA and save as PNG optimized Thanks to Dr. Sybren and Francesco for review and feedback
This commit is contained in:
parent
b2cfe46438
commit
b98771f067
@ -30,9 +30,15 @@ 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).convert('RGB')
|
im = Image.open(src)
|
||||||
im.thumbnail(settings['size'])
|
im.thumbnail(settings['size'], resample=Image.LANCZOS)
|
||||||
im.save(dst, format='JPEG', quality=75)
|
|
||||||
|
# If the source image has transparency, save as PNG
|
||||||
|
if im.mode == 'RGBA':
|
||||||
|
im.save(dst, format='PNG', optimize=True)
|
||||||
|
else:
|
||||||
|
im.save(dst, format='JPEG', optimize=True, quality=95)
|
||||||
|
|
||||||
width, height = im.size
|
width, height = im.size
|
||||||
|
|
||||||
thumb_info = {'size': size,
|
thumb_info = {'size': size,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user