KKNTR commited on
Commit
164e935
·
verified ·
1 Parent(s): dee044b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -11
app.py CHANGED
@@ -57,22 +57,30 @@ def get_pipe():
57
  return pipe
58
 
59
  # -------------------------
60
- # IMAGE RESIZE
61
  # -------------------------
62
  def resize_image(image: Image.Image) -> Image.Image:
63
  width, height = image.size
64
  if width == height:
65
- return image.resize((SQUARE_DIM, SQUARE_DIM), Image.LANCZOS)
66
- aspect_ratio = width / height
67
- if width > height:
68
- target_w = MAX_DIM
69
- target_h = int(target_w / aspect_ratio)
70
  else:
71
- target_h = MAX_DIM
72
- target_w = int(target_h * aspect_ratio)
73
- target_w = max(MIN_DIM, min(MAX_DIM, target_w))
74
- target_h = max(MIN_DIM, min(MAX_DIM, target_h))
75
- return image.resize((target_w, target_h), Image.LANCZOS)
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
  # -------------------------
78
  # VIDEO GENERATION
 
57
  return pipe
58
 
59
  # -------------------------
60
+ # IMAGE RESIZE (16-multiple)
61
  # -------------------------
62
  def resize_image(image: Image.Image) -> Image.Image:
63
  width, height = image.size
64
  if width == height:
65
+ w = h = SQUARE_DIM
 
 
 
 
66
  else:
67
+ aspect_ratio = width / height
68
+ if width > height:
69
+ w = MAX_DIM
70
+ h = int(w / aspect_ratio)
71
+ else:
72
+ h = MAX_DIM
73
+ w = int(h * aspect_ratio)
74
+
75
+ # Pyöristetään 16:lla jaolliseksi
76
+ w = (w // 16) * 16
77
+ h = (h // 16) * 16
78
+
79
+ # Clamp min/max
80
+ w = max(MIN_DIM, min(MAX_DIM, w))
81
+ h = max(MIN_DIM, min(MAX_DIM, h))
82
+
83
+ return image.resize((w, h), Image.LANCZOS)
84
 
85
  # -------------------------
86
  # VIDEO GENERATION