PyPhoto is implemented as the single file of Example 11-5, though it gets some utility
for free by reusing the thumbnail generation function of the viewer_thumbs module that
we originally wrote near the end of Chapter 8 in Example 8-45. To spare you from
having to flip back and forth too much, here’s a copy of the code of the thumbs function
imported and used here:
# imported from Chapter 8...
def makeThumbs(imgdir, size=(100, 100), subdir='thumbs'):
# returns a list of (image filename, thumb image object);
thumbdir = os.path.join(imgdir, subdir)
if not os.path.exists(thumbdir):
os.mkdir(thumbdir)
thumbs = []
for imgfile in os.listdir(imgdir):
thumbpath = os.path.join(thumbdir, imgfile)
if os.path.exists(thumbpath):
thumbobj = Image.open(thumbpath) # use already created
thumbs.append((imgfile, thumbobj))
else:
print('making', thumbpath)
imgpath = os.path.join(imgdir, imgfile)
try:
Figure 11-10. PyPhoto image view window
PyPhoto: An Image Viewer and Resizer | 721