Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -131,6 +131,23 @@ def upload_image_to_r2(image, account_id, access_key, secret_key, bucket_name):
|
|
131 |
buffer.seek(0)
|
132 |
s3.upload_fileobj(buffer, bucket_name, image_file)
|
133 |
print("upload finish", image_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
return image_file
|
136 |
|
|
|
131 |
buffer.seek(0)
|
132 |
s3.upload_fileobj(buffer, bucket_name, image_file)
|
133 |
print("upload finish", image_file)
|
134 |
+
|
135 |
+
# start to generate thumbnail
|
136 |
+
thumbnail = image.copy()
|
137 |
+
thumbnail_width = 256
|
138 |
+
aspect_ratio = image.height / image.width
|
139 |
+
thumbnail_height = int(thumbnail_width * aspect_ratio)
|
140 |
+
thumbnail = thumbnail.resize((thumbnail_width, thumbnail_height), Image.LANCZOS)
|
141 |
+
|
142 |
+
# Generate the thumbnail image filename
|
143 |
+
thumbnail_file = image_file.replace(".png", "_thumbnail.png")
|
144 |
+
|
145 |
+
# Save thumbnail to buffer and upload
|
146 |
+
thumbnail_buffer = BytesIO()
|
147 |
+
thumbnail.save(thumbnail_buffer, "PNG")
|
148 |
+
thumbnail_buffer.seek(0)
|
149 |
+
s3.upload_fileobj(thumbnail_buffer, bucket_name, thumbnail_file)
|
150 |
+
print("upload thumbnail finish", thumbnail_file)
|
151 |
|
152 |
return image_file
|
153 |
|