Python 裁剪后保存图像空白

Python 裁剪后保存图像空白,python,python-3.x,python-imaging-library,Python,Python 3.x,Python Imaging Library,所以我试着从浏览器中提取图像,第一张图像img.jpg保存得很好,但截屏sho.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'] # 90

所以我试着从浏览器中提取图像,第一张图像img.jpg保存得很好,但截屏sho.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的“最低限度”吗?

默认情况下,Selenium不会筛选整个页面

为了避开它,我用了

    element = driver.find_elements_by_id('idofelemtineeded')[0]
    element_png = element.screenshot_as_png
    with open("screen.png", "wb") as file:
        file.write(element_png)

变量
位置
大小
?硒元素的位置。x=902 y=1915尺寸也取自元素,其180 x 50我认为左边的数字大于图像的宽度,或者顶部大于图像的高度。