Table Of ContentPillow: Image Processing with Python
Michael Driscoll
Thisbookisforsaleathttp://leanpub.com/pillow
Thisversionwaspublishedon2021-03-18
ThisisaLeanpubbook.LeanpubempowersauthorsandpublisherswiththeLeanPublishing
process.LeanPublishingistheactofpublishinganin-progressebookusinglightweighttoolsand
manyiterationstogetreaderfeedback,pivotuntilyouhavetherightbookandbuildtractiononce
youdo.
©2020-2021MichaelDriscoll
Contents
AbouttheTechnicalReviewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
EthanFurman . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
AlessiaMarcolini . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Whoisthisbookfor? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
AbouttheAuthor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
BookSourceCode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
ReaderFeedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Errata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
CoverArt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Chapter1-PillowBasics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
OpeningImages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
SavingImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
ChangingCompressionDuringSaving. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
ChangingDPIDuringSaving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
ReadingMethods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
CreatingThumbnails . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
CreatinganImageViewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
WrappingUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Chapter2-Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
UnderstandingColor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
UsingPillowtoGetRGBValues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
GettingColorsfromImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
ChangingPixelColors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
ConvertingtoBlackandWhite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Creating4-ColorPhotos. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
CreatingaSepiaPhoto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
CreatinganImageConverterGUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
CONTENTS
WrappingUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Chapter3-GettingImageMetadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
GettingExifTagData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
GettingGPSExifData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
GettingTIFFTagData. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
CreatinganExifGUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
WrappingUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Chapter4-Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
TheBLURFilter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
TheCONTOURFilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
TheDETAILFilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
TheEDGE_ENHANCEFilters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
TheEMBOSSFilter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
TheFIND_EDGESFilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
TheSHARPENFilter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
TheSMOOTHFilters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
RankFilters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
MultiBandFilters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
TheBoxBlurFilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
TheGaussianBlurFilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
TheColor3DLUTFilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
TheUnsharpMaskFilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
UsingFiltersinaGUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
WrappingUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Chapter5-Cropping,Rotating&ResizingImages . . . . . . . . . . . . . . . . . . . . . . . . . 105
HowCoordinatesWorkinImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
CroppingImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
RotatingImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
MirroringImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
ResizingImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
ScalingImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
CreatinganImageRotatorGUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
WrappingUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Chapter6-EnhancingImageswithImageEnhance . . . . . . . . . . . . . . . . . . . . . . . . . 124
AdjustColorBalance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
AdjustImageContrast. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
AdjustImageBrightness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
AdjustImageSharpness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
EnhancingPhotoswithaGUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
WrappingUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
CONTENTS
Chapter7-CombiningImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
PastinganImage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
TilingImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
ConcatenatingImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
WatermarkinganImage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
CompositingImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
BlendingImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
CreatingaWatermarkGUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
WrappingUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Chapter8-DrawingShapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
CommonParameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
DrawingLines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
DrawingArcs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
DrawingChords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
DrawingEllipses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
DrawingPieSlices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
DrawingPolygons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
DrawingRectangles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
CreatingaDrawingGUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
WrappingUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
Chapter9-DrawingText. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
DrawingText . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
LoadingTrueTypeFonts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
ChangingTextColor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
DrawingMultipleLinesofText . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
AligningText . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
ChangingTextOpacity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
LearningAboutTextAnchors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
CreatingaTextDrawingGUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
WrappingUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Chapter10-ChannelOperations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
ImageChopAliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
AddingImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
UsingImageChops.darker() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
UsingImageChops.lighter() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
FindingDifferencesinImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
InvertingImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
UsingSoftLightonImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
UsingHardLightonImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
OverlayImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
CreatingaBlendingGUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
CONTENTS
WrappingUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Chapter11-TheImageOpsModule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
ApplyingAutomaticContrast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
ColorizingPhotos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
PaddinganImage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
AddingaBorder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
RemovingaBorder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
ScalinganImage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
EqualizingtheHistogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
SizingandCroppinganImage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
FlippinganImage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
MirroringanImage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
InvertinganImage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
PosterizeanImage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
SolarizeanImage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
TransposeImageUsingExifOrientation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
CreatinganImageOpsGUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
WrappingUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Chapter12-PillowIntegrationwithGUIToolkits. . . . . . . . . . . . . . . . . . . . . . . . . . 308
Kivy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
PySimpleGUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
PyQt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
Tkinter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
wxPython . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
WrappingUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
Chapter13-AlternativestoPillow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
NumPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
OpenCV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Wand(ImageMagickBindings) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
CroppingwithWand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
WrappingUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
Chapter14-BatchProcessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
CreatingaBatchCLIApplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
RunningtheBatchApplicationwithThreads . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
ModularizingYourCode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
AddingaGUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
WrappingUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Afterword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
About the Technical Reviewers
Ethan Furman
Ethan, a largely self-taught programmer, discovered Python around the turn of the century, but
wasn’t able to explore it for nearly a decade. When he finally did, he fell in love with its simple
syntax, lack of boiler-plate, and the ease with which one can express one’s ideas in code. After
writing a dbf library to aid in switching his company’s code over to Python, he authored PEP 409,
wrote the Enum implementation for PEP 435, and authored PEP 461. He was invited to be a core
developerafterPEP435,whichhehappilyaccepted.
Hethankshismotherforhisloveoflanguage,stories,andthewrittenword.
Alessia Marcolini
Alessia is a Data Science EIT Digital student at the Eindhoven University of Technology. She
is a Junior Data Scientist at HK3lab, working on machine learning/deep learning frameworks
to integrate multiple medical imaging modalities and different clinical data to get more precise
prognostic/diagnosticbiomarkersforhumanandveterinaryhealth.
ShehasbeenavolunteeroftheItalianPythonCommunitysince2017,helpingwiththeorganization
ofPyConItaly(thenationalPythonConference,hosting700+internationaldelegateseachyear).In
2018,shealsojoinedtheorganizationcommitteeofEuroSciPy,theEuropeanConferenceforPython
inScience.
Whennotcoding,shelovesdancinganddrinkingblackteaandgoodgin.
Acknowledgments
Writingabooktakesahugetimecommitment.Fortunately,Ihadacoupleofveryhelpfulpeopleright
out the gate. Ethan Furman joined me for this book once more as a technical reviewer and editor. I
alsohadAlessiaMarcolinihelpingoutasatechnicalreviewerandgivingmelotsoffeedback.Thank
yousomuch!
Mike Barnett (creator of PySimpleGUI) encouraged me to write a book on Pillow and has been
helpfulinfeedbackontheGUIexamplesinthebook.SteveBarneshasalsohelpedoutwithfinding
littlebugsormakinggoodsuggestionsthathavehelpedmakethechaptersbetter.
I’dalsoliketothankmybetareaders:
• JaseLindgren,anearlybetareader,whohelpedmefindsometyposandprovidedgoodfeedback
too.
• Ruud van der Ham also helped with some good comments about PySimpleGUI and Pillow as
well.
• RoyNeilsenwhoreviewedmanyofthechaptersinthebook
Thankyouallforyourhelp!
Alex Clark, the creator of the Pillow fork, has also been encouraging. Thank you to everyone who
hasbeenandwhoiscurrentlyacoredeveloperofPillow.Youareamazing!
AndtoanyonethatIamforgettingandtoyou,thankyoutoo!
Thankyouforreadingthisbook!
• Mike
Introduction
ThePythonprogramminglanguagehasthousandsofpackagesthatyoucaninstallfromthePython
PackageIndexthatyoucanusetoenhanceyourcode.Therearemanypopularpackagesforworking
with images in Python, such as scikit-image, OpenCV and NumPy. However, for this book, you
will be learning how to use the Pillow package, which is the friendly fork of the Python Imaging
Library.
The Python Imaging Library adds image processing capabilities to your Python installation. Pillow
is the Python 3 version of the Python Imaging Library. According to Pillow’s documentation, it
provides you with “extensive file format support, an efficient internal representation, and fairly
powerfulimageprocessingcapabilities.”
Bytheendofthisbook,youwillbeabletodoallofthefollowingtasks:
• Openimages
• Extracthistrogramdata
• Extractimagemetadata
• Applyimagetransforms
• Addfilters
• Cropimages
• Enhanceimages
• Combineimages
• Basicdrawings
• andmore!
Pillow is a powerful library that you can use for general purpose image processing. If you need to
dopixel-by-pixeloperationswhereyouneedtoexamineorchangepixels,youwillfindthatPillow
isrelativelyslow.YoumaywanttolookatalibrarylikeNumPyinsteadforthatusecase.
YouwillalsobeusingthePySimpleGUItoolkittobuildlittleapplicationsincombinationwithPillow.
The PySimpleGUI portions of the books are completely optional, but are helpful in demonstrating
theconceptsyouwillbelearningabout.Youcanskipthementirelyifyouwantto.
Who is this book for?
Thisbookistargetedatintermediateleveldevelopers.Theidealpersonreadingthisbookwillknow
thePythonlanguagealreadyandunderstandhowtoinstall3rdpartypackages.
Introduction 4
About the Author
MikeDriscollhasbeenprogrammingwiththePythonlanguageformorethanadecade.WhenMike
isn’t programming for work, he writes about Python on his blog¹ and contributes to Real Python.
He has worked with Packt Publishing and No Starch Press as a technical reviewer. Mike has also
writtenseveralbooks.
YoucanseeafulllistingofMike’sbooksonhisblog²too.
Conventions
Therearen’talotofspecialconventionsinthisbook.Themainoneyouneedtobeawareofisthat
codeblockswilllooklikethis:
1 import PIL
2
3 # do something fun!
Whenreferringtocodeinasentenceyouwillseeitinmonospace.
Imageswillbemarkedwithachapterandimagenumberforeasyreference.
Otherthanthat,therearenoconventions!
Requirements
ThisbookiswrittenforPython3.TheexamplesmayworkinPython2,butarenottestedinPython
2.
YouwillneedPillowtobeabletousetheexamplesinthisbook.InstallingPillowcanbedoneusing
pip:
1 python3 -m pip install --upgrade pip
2 python3 -m pip install --upgrade Pillow
LinuxuserscanalsoinstallPillowbyusingtheirLinuxpackagemanagerandinstallingpython-imaging
iftheyprefer.
If you want to install Pillow from source, you should refer to the documentation³ for the latest
instructions.
IfyouwanttobeabletousethePySimpleGUIexamplesinthisbook,thenyouwillneedtoinstall
itaswellusingthefollowingcommand:
¹https://www.blog.pythonlibrary.org/
²https://www.blog.pythonlibrary.org/books/
³https://pillow.readthedocs.io/en/stable/installation.html