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: