Appendix A. Py Art
Well, art is art, isn’t it? Still, on the other hand, water is water! And east is east and west is west, and if you take cranberries and stew them like applesauce, they taste much more like prunes than rhubarb does.
Groucho Marx
Maybe you’re an artist, or a musician. Or maybe you just want to try something creative and different.
These first three appendices are explorations of some common human endeavors using Python. If your interest lies in any of these areas, you might get some ideas from the chapters, or the urge to try something new.
2-D Graphics
All computer languages have been applied to computer graphics to some degree. Many of the heavy-duty platforms in this chapter were written in C or C++ for speed, but added Python libraries for productivity. Let’s begin by looking at some 2-D imaging libraries.
Standard Library
Only a few graphics-related modules are in the standard library. Here are two of them:
imghdr
-
This module detects the file type of some image files.
colorsys
-
This module converts colors between various systems: RGB, YIQ, HSV, and HLS.
If you downloaded the O’Reilly logo to a local file called oreilly.png, you could run this:
>>>
import
imghdr
>>>
imghdr
.
what
(
'oreilly.png'
)
'png'
To do anything serious with graphics in Python, we need to get some third-party packages. Let’s see what’s out there.
PIL and Pillow
For many years, the Python Image Library (PIL), although not in the standard library, has been Python’s best-known 2-D ...
Get Introducing Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.