900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > python裁剪图片并保存_Python PIL:如何保存裁剪后的图像?

python裁剪图片并保存_Python PIL:如何保存裁剪后的图像?

时间:2018-10-28 23:47:47

相关推荐

python裁剪图片并保存_Python PIL:如何保存裁剪后的图像?

这是一个全面工作的aswer与一个新版本的PIL 1.1.7。裁剪坐标现在是左上角和右下角(而不是x、y、宽度和高度)。

python的版本号是:2.7.15

对于PIL:1.1.7# -*- coding: utf-8 -*-

from PIL import Image

import PIL, sys

print sys.version, PIL.VERSION

for fn in ['im000001.png']:

center_x = 200

center_y = 500

half_width = 500

half_height = 100

imageObject = Image.open(fn)

#cropped = imageObject.crop((200, 100, 400, 300))

cropped = imageObject.crop((center_x - half_width,

center_y - half_height,

center_x + half_width,

center_y + half_height,

))

cropped.save('crop_' + fn, 'PNG')

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。