aboutsummaryrefslogtreecommitdiff
path: root/bot.py
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2023-02-28 23:45:29 -0800
committerclarkzjw <[email protected]>2023-02-28 23:45:29 -0800
commita975ef06d47d17debcb766a6af4c03ff5f8859ed (patch)
treec766c0e6c7e37a4b7a07bb3c1632129411fe5cbe /bot.py
parent9cf9a5b71890e4fdb3363e3709050ae6ce26b092 (diff)
downloadphoto-a975ef06d47d17debcb766a6af4c03ff5f8859ed.tar.gz
use lossy webp compression
Diffstat (limited to 'bot.py')
-rw-r--r--bot.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/bot.py b/bot.py
index 20529c0..9d9b322 100644
--- a/bot.py
+++ b/bot.py
@@ -132,7 +132,7 @@ async def process(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
132 try: 132 try:
133 im = Image.open(img) 133 im = Image.open(img)
134 output = io.BytesIO() 134 output = io.BytesIO()
135 im.save(output, format="webp", lossless=True, quality=100) 135 im.save(output, format="webp", lossless=False, quality=80)
136 136
137 now = datetime.now().strftime("%Y-%m-%d-%H-%M-%S") 137 now = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
138 key_name = "{}-{}.webp".format(now, filename) 138 key_name = "{}-{}.webp".format(now, filename)
@@ -145,8 +145,8 @@ async def process(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
145 ratio=im.width / im.height, 145 ratio=im.width / im.height,
146 orientation="landscape" if im.width > im.height else "portrait", 146 orientation="landscape" if im.width > im.height else "portrait",
147 path="https://pixelstatic.jinwei.me/{}".format(key_name), 147 path="https://pixelstatic.jinwei.me/{}".format(key_name),
148 caption="dsadas", 148 caption="",
149 alt="dsada", 149 alt="",
150 createdAt=datetime.now(), 150 createdAt=datetime.now(),
151 uploadedAt=datetime.now()) 151 uploadedAt=datetime.now())
152 152
@@ -154,13 +154,9 @@ async def process(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
154 upload_to_s3(photo.fileId, output.read()) 154 upload_to_s3(photo.fileId, output.read())
155 155
156 write_json() 156 write_json()
157 await update.message.reply_markdown_v2(text="Sending processed result") 157 await update.message.reply_markdown_v2(text="Done")
158 158
159 await context.bot.send_document(chat_id=update.message.chat_id, 159 except Exception:
160 filename="{}-result.{}".format(filename, file_ext),
161 document=output.getvalue())
162
163 except Exception as e:
164 await update.message.reply_markdown_v2(text="Error:\n```{}```".format(traceback.format_exc())) 160 await update.message.reply_markdown_v2(text="Error:\n```{}```".format(traceback.format_exc()))
165 161
166 162
Powered by cgit v1.2.3 (git 2.41.0)