From 43b1f64c7de82bb0b1f72881120aaba20a845e18 Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Mon, 14 Jun 2021 23:23:50 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20speedtest=20Image=20remove?= =?UTF-8?q?d=20white=20border.=20(#86)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ⚡️ speedtest 图片去掉白色边框。 --- pagermaid/modules/status.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pagermaid/modules/status.py b/pagermaid/modules/status.py index 61de76a..0b473b9 100644 --- a/pagermaid/modules/status.py +++ b/pagermaid/modules/status.py @@ -1,6 +1,8 @@ """ PagerMaid module that contains utilities related to system status. """ from json import loads +from PIL import Image +from requests import get from os import remove, popen from datetime import datetime from speedtest import distance, Speedtest, ShareResultsConnectFailure, ShareResultsSubmitFailure, NoMatchedServers, \ @@ -150,7 +152,21 @@ async def speedtest(context): f"Latency: `{result['ping']}` \n" 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()