aboutsummaryrefslogtreecommitdiff
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
parent9cf9a5b71890e4fdb3363e3709050ae6ce26b092 (diff)
downloadphoto-a975ef06d47d17debcb766a6af4c03ff5f8859ed.tar.gz
use lossy webp compression
-rw-r--r--.gitignore2
-rw-r--r--_data/photos.json1
-rw-r--r--bot.py14
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 @@
1database/
2env
1_drafts/ 3_drafts/
2_site/ 4_site/
3.DS_Store 5.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:
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)