【问题标题】:Pillow saving image blank after cropping裁剪后枕头保存图像空白
【发布时间】: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 的“最低限度”吗?

【问题讨论】:

  • 变量locationsize是什么?
  • 取自硒的元素的位置。 x=902 y=1915 大小也取自元素及其 180 x 50
  • 我认为left这个数字大于你图片的宽度,或者顶部大于你图片的高度。

标签: python python-3.x python-imaging-library


【解决方案1】:

默认情况下,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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-08
    • 1970-01-01
    • 2020-12-11
    • 2021-07-02
    • 2018-05-15
    相关资源
    最近更新 更多