Skip to content

Commit 75e3fdb

Browse files
authored
Update README.md
1 parent f2452f2 commit 75e3fdb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,20 @@ import matplotlib
198198
matplotlib.use('Agg')
199199
import matplotlib.pyplot as plt
200200

201+
def resize_short_edge(image, target_size=2048):
202+
if isinstance(image, str):
203+
image = Image.open(image)
204+
width, height = image.size
205+
short_edge = min(width, height)
206+
207+
if short_edge >= target_size:
208+
return image
209+
scale = target_size / short_edge
210+
new_width = int(width * scale)
211+
new_height = int(height * scale)
212+
resized_image = image.resize((new_width, new_height))
213+
return resized_image
214+
201215

202216
img_root = "cat_dfclor.jpg"
203217
image = Image.open(img_root).convert("RGB")

0 commit comments

Comments
 (0)