使用PIL进行图像裁剪无法在远程Windows桌面上按预期裁剪

2024-04-26 12:13:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python新手,非常感谢您的帮助。我使用seleniumwebdriver开发了一个python脚本,它可以生成报告并从网站上获取快照。我在其他人的笔记本电脑上测试过它的裁剪是否正确,但当我在远程桌面(windows)上部署它并运行它时,裁剪就搞砸了。你知道吗

I have pasted code here .I am using two elements from flex taking those point as reference point i have defined crop points so somehow i am not hard coding the point.

element=WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,'//*[@id="LineChart"]')))
location = element.location
size = element.size
height_header=size['height']
top_wan=top = location['y']
element=WebDriverWait(driver,10).until(EC.presence_of_element_located((By.ID,'chartContainer')))
location = element.location
size = element.size
        driver.save_screenshot(fold_path+'\\Reports\\Screenshots\\LAN_traffic_by_apps_bidir'+str(x)+'_for_ref_site_'+str(ref_site)+'.png') # saves screenshot of entire page. 

im=Image.open(fold_path+'\\Reports\\Screenshots\\LAN_traffic_by_apps_bidir'+str(x)+'_for_ref_site_'+str(ref_site)+'.png')
left = location['x']
top = location['y']+ 3 *height_header + 4
right = location['x'] + size['width']
bottom= location['y'] + 25 *height_header - 2
height_all_row=size['height']
im = im.crop((left, top, right, bottom)) # defines crop points

Tags: ofcroprefsizetophavedriversite