import os
from PIL import Image, ImageFilter

target_path = os.path.join('.', 'image')
image_name = 'original.jpg'

# 打开一个jpg图像文件，注意是当前路径:
im = Image.open(os.path.join(target_path, image_name))
# 获得图像尺寸:
w, h = im.size
print('Original image size: %sx%s' % (w, h))
# 缩放到50%:
im.thumbnail((w//2, h//2))
print('Resize image to: %sx%s' % (w//2, h//2))
# 把缩放后的图像用jpeg格式保存:
im.save(os.path.join(target_path, 'thumbnail.jpg'), 'jpeg')
# 应用模糊滤镜:
im2 = im.filter(ImageFilter.BLUR)
im2.save(os.path.join(target_path, 'blur.jpg'), 'jpeg')
