Skip to content

Commit 2205809

Browse files
authored
Update README_en.md
1 parent 75e3fdb commit 2205809

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

README_en.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,19 @@ import matplotlib
195195
matplotlib.use('Agg')
196196
import matplotlib.pyplot as plt
197197

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

199212
img_root = "cat_dfclor.jpg"
200213
image = Image.open(img_root).convert("RGB")

0 commit comments

Comments
 (0)