是否有一种显而易见的方法可以解决这个问题?我只是想制作缩略图.
目前我正在使用:
os.chdir(album.path)
images = glob.glob('*.*')
# thumbs size
size = 80,80
for image in images:
#create thumb
file, ext = os.path.splitext(image)
im = Image.open(os.path.join(album.path,image))
im.thumbnail(size, Image.ANTIALIAS)
thumb_path = os.path.join(album.path, 'thumbs', file + ".thumb" + ".jpeg")
im.save(thumb_path)
Run Code Online (Sandbox Code Playgroud)
虽然这有效,但我最终得到了不同尺寸的图像(有些是肖像,有些是风景),但我希望所有图像都具有精确的尺寸.也许是一个明智的裁剪?
更新:
我不介意裁剪一小部分图像.当我说明智的裁剪时,我的意思是这样的algorythm:
if image is portrait:
make width 80px
crop the height (will be more than 80px)
else if image is landscape:
make height 80px
crop the width to 80px (will be more than 80px)
Run Code Online (Sandbox Code Playgroud)