Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -90,7 +90,7 @@ def home_page():
|
|
| 90 |
</head>
|
| 91 |
<body>
|
| 92 |
<img class="banner" src="/static/images/banner.jpg" alt="Banner" width="100%">
|
| 93 |
-
<h2>
|
| 94 |
<p>Please select an option below:</p>
|
| 95 |
<ul>
|
| 96 |
<li><a href="/demo">Demo</a></li>
|
|
@@ -110,17 +110,17 @@ def demo_page():
|
|
| 110 |
# Process the first image
|
| 111 |
response = requests.get(url1)
|
| 112 |
img1 = Image.open(BytesIO(response.content)).convert("RGB")
|
| 113 |
-
|
| 114 |
output1 = BytesIO()
|
| 115 |
-
|
| 116 |
encoded_img1 = base64.b64encode(output1.getvalue()).decode("utf-8")
|
| 117 |
|
| 118 |
# Process the second image
|
| 119 |
response = requests.get(url2)
|
| 120 |
img2 = Image.open(BytesIO(response.content)).convert("RGB")
|
| 121 |
-
|
| 122 |
output2 = BytesIO()
|
| 123 |
-
|
| 124 |
encoded_img2 = base64.b64encode(output2.getvalue()).decode("utf-8")
|
| 125 |
|
| 126 |
return f"""
|
|
@@ -132,7 +132,7 @@ def demo_page():
|
|
| 132 |
<body>
|
| 133 |
<img class="banner" src="/static/images/banner.jpg" alt="Banner" width="100%">
|
| 134 |
<h2>Square Image Demo</h2>
|
| 135 |
-
<p>Image will be
|
| 136 |
<h3>Result 1:</h3>
|
| 137 |
<img src="data:image/jpeg;base64,{encoded_img1}" />
|
| 138 |
<h3>Result 2:</h3>
|
|
@@ -170,18 +170,18 @@ async def upload_file(file: UploadFile = File(...)):
|
|
| 170 |
# Await file upload
|
| 171 |
contents = await file.read()
|
| 172 |
img = Image.open(BytesIO(contents)).convert("RGB")
|
| 173 |
-
|
| 174 |
|
| 175 |
-
# Save the
|
| 176 |
output = BytesIO()
|
| 177 |
-
|
| 178 |
output.seek(0)
|
| 179 |
|
| 180 |
# Encode the full-size image for download
|
| 181 |
full_size_encoded_img = base64.b64encode(output.getvalue()).decode("utf-8")
|
| 182 |
|
| 183 |
# Resize the image for display (512px by 512px)
|
| 184 |
-
display_img =
|
| 185 |
display_img.thumbnail((512, 512)) # Resize for display
|
| 186 |
display_output = BytesIO()
|
| 187 |
display_img.save(display_output, format="JPEG")
|
|
@@ -200,9 +200,9 @@ async def upload_file(file: UploadFile = File(...)):
|
|
| 200 |
</head>
|
| 201 |
<body>
|
| 202 |
<img class="banner" src="/static/images/banner.jpg" alt="Banner" width="100%">
|
| 203 |
-
<h2>Image successfully
|
| 204 |
<img src='data:image/jpeg;base64,{display_encoded_img}' width="512" height="512" />
|
| 205 |
-
<p><a href="data:image/jpeg;base64,{full_size_encoded_img}" download="
|
| 206 |
Download Full-Size Image</a></p>
|
| 207 |
<p><a href="/">Back</a></p>
|
| 208 |
</body>
|
|
|
|
| 90 |
</head>
|
| 91 |
<body>
|
| 92 |
<img class="banner" src="/static/images/banner.jpg" alt="Banner" width="100%">
|
| 93 |
+
<h2>Rectangle and Fill Image App</h2>
|
| 94 |
<p>Please select an option below:</p>
|
| 95 |
<ul>
|
| 96 |
<li><a href="/demo">Demo</a></li>
|
|
|
|
| 110 |
# Process the first image
|
| 111 |
response = requests.get(url1)
|
| 112 |
img1 = Image.open(BytesIO(response.content)).convert("RGB")
|
| 113 |
+
rectangled_img1 = fill_rectangle_cropper_cropper(img1)
|
| 114 |
output1 = BytesIO()
|
| 115 |
+
rectangled_img1.save(output1, format="JPEG")
|
| 116 |
encoded_img1 = base64.b64encode(output1.getvalue()).decode("utf-8")
|
| 117 |
|
| 118 |
# Process the second image
|
| 119 |
response = requests.get(url2)
|
| 120 |
img2 = Image.open(BytesIO(response.content)).convert("RGB")
|
| 121 |
+
rectangled_img2 = fill_rectangle_cropper_cropper(img2)
|
| 122 |
output2 = BytesIO()
|
| 123 |
+
rectangled_img2.save(output2, format="JPEG")
|
| 124 |
encoded_img2 = base64.b64encode(output2.getvalue()).decode("utf-8")
|
| 125 |
|
| 126 |
return f"""
|
|
|
|
| 132 |
<body>
|
| 133 |
<img class="banner" src="/static/images/banner.jpg" alt="Banner" width="100%">
|
| 134 |
<h2>Square Image Demo</h2>
|
| 135 |
+
<p>Image will be rectangled with color filler where applicable.</p>
|
| 136 |
<h3>Result 1:</h3>
|
| 137 |
<img src="data:image/jpeg;base64,{encoded_img1}" />
|
| 138 |
<h3>Result 2:</h3>
|
|
|
|
| 170 |
# Await file upload
|
| 171 |
contents = await file.read()
|
| 172 |
img = Image.open(BytesIO(contents)).convert("RGB")
|
| 173 |
+
rectangled_img = fill_rectangle_cropper_cropper(img)
|
| 174 |
|
| 175 |
+
# Save the rectangle image (original size)
|
| 176 |
output = BytesIO()
|
| 177 |
+
rectangled_img.save(output, format="JPEG")
|
| 178 |
output.seek(0)
|
| 179 |
|
| 180 |
# Encode the full-size image for download
|
| 181 |
full_size_encoded_img = base64.b64encode(output.getvalue()).decode("utf-8")
|
| 182 |
|
| 183 |
# Resize the image for display (512px by 512px)
|
| 184 |
+
display_img = rectangled_img.copy()
|
| 185 |
display_img.thumbnail((512, 512)) # Resize for display
|
| 186 |
display_output = BytesIO()
|
| 187 |
display_img.save(display_output, format="JPEG")
|
|
|
|
| 200 |
</head>
|
| 201 |
<body>
|
| 202 |
<img class="banner" src="/static/images/banner.jpg" alt="Banner" width="100%">
|
| 203 |
+
<h2>Image successfully rectangled!</h2>
|
| 204 |
<img src='data:image/jpeg;base64,{display_encoded_img}' width="512" height="512" />
|
| 205 |
+
<p><a href="data:image/jpeg;base64,{full_size_encoded_img}" download="rectangled_image.jpg">
|
| 206 |
Download Full-Size Image</a></p>
|
| 207 |
<p><a href="/">Back</a></p>
|
| 208 |
</body>
|