Fix JPEG thumbnail generation (#556)
Fix JPEG thumbnail generation (#556)

Since Pillow 4.2, an exception is thrown when trying to save an image with an alpha channel to JPEG (because it cannot store this channel).

This simply checks for an exception and tries again without the alpha channel. Unfortunately Pillow just uses IOError instead of a specific exception type, and I think that checking the exception message is fragile. If the IOError has another cause, such as the disk being full, then the second save will probably fail the same way.
Titan-C/sphinx-gallery,Titan-C/sphinx-gallery,Eric89GXL/sphinx-gallery,sphinx-gallery/sphinx-gallery,Eric89GXL/sphinx-gallery,sphinx-gallery/sphinx-gallery