From a975ef06d47d17debcb766a6af4c03ff5f8859ed Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Tue, 28 Feb 2023 23:45:29 -0800 Subject: use lossy webp compression --- .gitignore | 2 ++ _data/photos.json | 1 + bot.py | 14 +++++--------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index f157e65..afd5147 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +database/ +env _drafts/ _site/ .DS_Store diff --git a/_data/photos.json b/_data/photos.json index e69de29..9a46673 100644 --- a/_data/photos.json +++ b/_data/photos.json @@ -0,0 +1 @@ +[{"guid": "61881B2D-1B87-4C7B-B4EB-063836F10C90", "fileId": "2023-02-28-23-39-47-IMG_0070.webp", "width": 5280, "height": 3512, "ratio": 1.5034168564920274, "orientation": "landscape", "path": "https://pixelstatic.jinwei.me/2023-02-28-23-39-47-IMG_0070.webp", "caption": "", "alt": "", "createdAt": "2023-02-28T23:39:47.000Z", "uploadedAt": "2023-02-28T23:39:47.000Z"}, {"guid": "B77DFD0A-342F-41F6-97ED-4FB289149A77", "fileId": "2023-02-28-23-43-55-IMG_0021.webp", "width": 5928, "height": 3992, "ratio": 1.4849699398797596, "orientation": "landscape", "path": "https://pixelstatic.jinwei.me/2023-02-28-23-43-55-IMG_0021.webp", "caption": "", "alt": "", "createdAt": "2023-02-28T23:43:55.000Z", "uploadedAt": "2023-02-28T23:43:55.000Z"}] \ No newline at end of file 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: try: im = Image.open(img) output = io.BytesIO() - im.save(output, format="webp", lossless=True, quality=100) + im.save(output, format="webp", lossless=False, quality=80) now = datetime.now().strftime("%Y-%m-%d-%H-%M-%S") key_name = "{}-{}.webp".format(now, filename) @@ -145,8 +145,8 @@ async def process(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: ratio=im.width / im.height, orientation="landscape" if im.width > im.height else "portrait", path="https://pixelstatic.jinwei.me/{}".format(key_name), - caption="dsadas", - alt="dsada", + caption="", + alt="", createdAt=datetime.now(), uploadedAt=datetime.now()) @@ -154,13 +154,9 @@ async def process(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: upload_to_s3(photo.fileId, output.read()) write_json() - await update.message.reply_markdown_v2(text="Sending processed result") + await update.message.reply_markdown_v2(text="Done") - await context.bot.send_document(chat_id=update.message.chat_id, - filename="{}-result.{}".format(filename, file_ext), - document=output.getvalue()) - - except Exception as e: + except Exception: await update.message.reply_markdown_v2(text="Error:\n```{}```".format(traceback.format_exc())) -- cgit v1.2.3