️ speedtest Image removed white border. (#86)

* ️ speedtest 图片去掉白色边框。
This commit is contained in:
Xtao_dada 2021-06-14 23:23:50 +08:00 committed by GitHub
parent 6be2f090bc
commit 43b1f64c7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,8 @@
""" PagerMaid module that contains utilities related to system status. """ """ PagerMaid module that contains utilities related to system status. """
from json import loads from json import loads
from PIL import Image
from requests import get
from os import remove, popen from os import remove, popen
from datetime import datetime from datetime import datetime
from speedtest import distance, Speedtest, ShareResultsConnectFailure, ShareResultsSubmitFailure, NoMatchedServers, \ from speedtest import distance, Speedtest, ShareResultsConnectFailure, ShareResultsSubmitFailure, NoMatchedServers, \
@ -150,7 +152,21 @@ async def speedtest(context):
f"Latency: `{result['ping']}` \n" f"Latency: `{result['ping']}` \n"
f"Timestamp: `{result['timestamp']}`" f"Timestamp: `{result['timestamp']}`"
) )
await context.client.send_file(context.chat_id, result['share'], caption=des) # 开始处理图片
data = get(result['share']).content
with open('speedtest.jpg', mode='wb') as f:
f.write(data)
img = Image.open('speedtest.jpg')
c = img.crop((17, 11, 727, 389))
c.save('speedtest.jpg')
try:
msg = await context.client.send_file(context.chat_id, 'speedtest.jpg', caption=des)
except:
return
try:
remove('speedtest.jpg')
except:
pass
await context.delete() await context.delete()