patrickligardes commited on
Commit
f38a0d1
ยท
verified ยท
1 Parent(s): 9c1eef3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -32
app.py CHANGED
@@ -141,39 +141,20 @@ 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
- 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 = 0 # Start from the top of the image to keep the face in view
159
- right = (width + target_width) / 2
160
- bottom = target_height
161
-
162
- # Ensure bottom does not exceed image height
163
- bottom = min(height, bottom)
164
-
165
- # Crop the image
166
- cropped_img = human_img_orig.crop((left, top, right, bottom))
167
- crop_size = cropped_img.size
168
-
169
- # Resize the cropped image
170
- human_img = cropped_img.resize((768, 1024))
171
-
172
- # Example usage of crop_size
173
- out_img = images[0].resize(crop_size)
174
- human_img_orig.paste(out_img, (int(left), int(top)))
175
-
176
-
177
  else:
178
  human_img = human_img_orig.resize((768,1024))
179
 
 
141
 
142
  if is_checked_crop:
143
  width, height = human_img_orig.size
144
+ aspect_ratio = width / height
145
+
146
+ if not (0.45 < aspect_ratio < 0.46):
147
+ target_width = int(min(width, height * (3 / 4)))
148
+ target_height = int(min(height, width * (4 / 3)))
149
+ left = (width - target_width) / 2
150
+ top = (height - target_height) / 2
151
+ right = (width + target_width) / 2
152
+ bottom = (height + target_height) / 2
153
+ cropped_img = human_img_orig.crop((left, top, right, bottom))
154
+ crop_size = cropped_img.size
155
+ human_img = cropped_img.resize((768, 1024))
156
  else:
157
+ human_img = human_img_orig.resize((768,1024))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  else:
159
  human_img = human_img_orig.resize((768,1024))
160