第19章
# 19.3 项目:添加徽标操作图像
### 第4步:添加徽标,并保存更改
第四加logo的时候出现了一些问题
书中给的代码
# ! python3
# resizeAndAddLogo.py - Resizes all images in current working directorty to fit
# in a 300X300 square,and adds catlogo.png to the lower- right corrner.
import os
from PIL import Image
SQUARE_FIT_SIZE = 300
LOGO_FILENAME = 'catlogo.png'
logoIm =Image.open(LOGO_FILENAME)
logoWidth,logoHeight = logoIm.size
os.makedirs('withLogo',exist_ok = True)
# Loop over all files in the working directory.
for filename in os.listdir('.'):
if not (filename.endswith('.png') or filename.endswith('.jpg'))\
or filename == LOGO_FILENAME:
continue # skip non-impage files and the logo file itself
im = Image.open(filename)
width,height = im.size
# Check if image needs to be resized.
if width > SQUARE_FIT_SIZE