是否有一种显而易见的方法可以解决这个问题?我只是想制作缩略图.
我有以下示例,我希望使用 Pillow 调整图像大小。
正如您所看到的,我有用户传入的新宽度,但没有高度。我如何计算出该图像的新高度,同时保持相同的纵横比?
图像不是正方形,而是矩形,因此高度和宽度不会相同。
orig_image = Image.open(get_full_path(file.relative_path))
new_width = int(request.args.get('w'))
# TODO resize properly, we need to work out new image height
resized_image = orig_image.resize((new_width, ), Image.ANTIALIAS)
Run Code Online (Sandbox Code Playgroud)