Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -141,22 +141,27 @@ def start_tryon(dict,garm_img,garment_des,is_checked,is_checked_crop,denoise_ste
|
|
141 |
|
142 |
if is_checked_crop:
|
143 |
width, height = human_img_orig.size
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
148 |
else:
|
149 |
-
|
150 |
-
|
|
|
|
|
|
|
151 |
left = (width - target_width) / 2
|
152 |
top = (height - target_height) / 2
|
153 |
right = (width + target_width) / 2
|
154 |
bottom = (height + target_height) / 2
|
|
|
|
|
155 |
cropped_img = human_img_orig.crop((left, top, right, bottom))
|
156 |
-
crop_size = cropped_img.size
|
157 |
human_img = cropped_img.resize((768, 1024))
|
158 |
-
|
159 |
-
|
160 |
|
161 |
else:
|
162 |
human_img = human_img_orig.resize((768,1024))
|
|
|
141 |
|
142 |
if is_checked_crop:
|
143 |
width, height = human_img_orig.size
|
144 |
+
target_aspect_ratio = 3 / 4
|
145 |
+
|
146 |
+
# Determine the new dimensions that fit the target aspect ratio
|
147 |
+
if width / height > target_aspect_ratio:
|
148 |
+
# Image is wider than the target aspect ratio
|
149 |
+
target_height = height
|
150 |
+
target_width = int(height * target_aspect_ratio)
|
151 |
else:
|
152 |
+
# Image is taller or equal to the target aspect ratio
|
153 |
+
target_width = width
|
154 |
+
target_height = int(width / target_aspect_ratio)
|
155 |
+
|
156 |
+
# Calculate the cropping box
|
157 |
left = (width - target_width) / 2
|
158 |
top = (height - target_height) / 2
|
159 |
right = (width + target_width) / 2
|
160 |
bottom = (height + target_height) / 2
|
161 |
+
|
162 |
+
# Crop and resize the image
|
163 |
cropped_img = human_img_orig.crop((left, top, right, bottom))
|
|
|
164 |
human_img = cropped_img.resize((768, 1024))
|
|
|
|
|
165 |
|
166 |
else:
|
167 |
human_img = human_img_orig.resize((768,1024))
|