【发布时间】:2020-07-20 14:57:04
【问题描述】:
所以我试图从浏览器中提取图像,第一张图像 img.jpg 完美保存,但裁剪后的 screenshot.jpg 保存为空白 img。
我为此使用 PIL 库,图像保存为 180x50,但它是空白的。
image = Image.open("img.jpg")
rgb_im = image.convert('RGB')
left = location['x'] # 902
top = location['y'] # 1915
right = location['x'] + size['width'] # 902+180
bottom = location['y'] + size['height'] # 1915+50
im = rgb_im.crop((left, top, right, bottom)) # defines crop points
im.save('screenshot.jpg') # saves new cropped image
这可能是 pil 的“最低限度”吗?
【问题讨论】:
-
变量
location和size是什么? -
取自硒的元素的位置。 x=902 y=1915 大小也取自元素及其 180 x 50
-
我认为
left这个数字大于你图片的宽度,或者顶部大于你图片的高度。
标签: python python-3.x python-imaging-library