-
Book Overview & Buying
-
Table Of Contents
Python Automation Cookbook - Third Edition
By :
Probably the most common form of data that is not text is image data. Images have their own set of specific metadata that can be read and used to filter values or perform other operations.
The main challenge is dealing with multiple image formats and different metadata specifications. We'll show in this recipe how to get information from both JPEG and PNG files, and see how the same information can be encoded differently.
The best general toolkit for dealing with images in Python is, arguably, Pillow. This library allows you to easily read files in the most common formats, as well as perform operations on them. Pillow started as a fork of PIL (Python Imaging Library), a previous module that became stagnant some years ago.
We will also use the xmltodict module to transform some data from XML into a more convenient dictionary. We will add both modules to requirements.txt and reinstall them in the virtual environment:
$ echo "Pillow==12.0.0" ...