From ffae64dd78d6fa77c1209c783aeb28d14f1b1d40 Mon Sep 17 00:00:00 2001 From: Serge Koval Date: Wed, 16 Oct 2019 18:53:35 -0400 Subject: [PATCH] Fixed pillow image conversion --- flask_admin/form/upload.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flask_admin/form/upload.py b/flask_admin/form/upload.py index b58204647..4a950b6f1 100644 --- a/flask_admin/form/upload.py +++ b/flask_admin/form/upload.py @@ -465,7 +465,10 @@ def _resize(self, image, size): return image def _save_image(self, image, path, format='JPEG'): - if image.mode not in ('RGB', 'RGBA'): + # New Pillow versions require RGB format for JPEGs + if format == 'JPEG': + image = image.convert('RGB') + elif image.mode not in ('RGB', 'RGBA'): image = image.convert('RGBA') with open(path, 'wb') as fp: