Fixing Images Uploaded in Python Webapps
This a Python function method to “fix” images uploaded by webapp users. By fix, we mean,
Correct the image orientation (a somewhat nasty issue concerning JPEGs taken by cell phone cameras)
Strip the image of everything but its basic data (EXIF tags, gif animations, etc.)
Optionally restrict the width and/or height of the image, which is proportionally downsized to fit the tighter constraint using a high-quality downsampling algorithm
Usage documentation and an example are provided. You’ll need to install Pillow (python image library). Be sure to first install the external libraries to support additional image formats, etc. (don’t worry if they don’t all install successfully). See the Pillow Installation Instructions.
This code is free to use for any purpose.