primerz commited on
Commit
ed5ed53
·
verified ·
1 Parent(s): 6bb6517

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +5 -5
utils.py CHANGED
@@ -11,10 +11,10 @@ captioner_processor = None
11
  captioner_model = None
12
 
13
  def resize_image_to_1mp(image):
14
- """Resizes image to approx 1MP (e.g., 1024x1024) preserving aspect ratio."""
15
  image = image.convert("RGB")
16
  w, h = image.size
17
- target_pixels = 1024 * 1024
18
  aspect_ratio = w / h
19
 
20
  # Calculate new dimensions
@@ -22,11 +22,11 @@ def resize_image_to_1mp(image):
22
  new_w = int(new_h * aspect_ratio)
23
 
24
  # Ensure divisibility by 48 for efficiency
25
- new_w = (new_w // 48) * 48
26
- new_h = (new_h // 48) * 48
27
 
28
  if new_w == 0 or new_h == 0:
29
- new_w, new_h = 1024, 1024 # Fallback
30
 
31
  return image.resize((new_w, new_h), Image.LANCZOS)
32
 
 
11
  captioner_model = None
12
 
13
  def resize_image_to_1mp(image):
14
+ """Resizes image to approx 1MP (e.g., 768x768) preserving aspect ratio."""
15
  image = image.convert("RGB")
16
  w, h = image.size
17
+ target_pixels = 768 * 768
18
  aspect_ratio = w / h
19
 
20
  # Calculate new dimensions
 
22
  new_w = int(new_h * aspect_ratio)
23
 
24
  # Ensure divisibility by 48 for efficiency
25
+ new_w = (new_w // 64) * 64
26
+ new_h = (new_h // 64) * 64
27
 
28
  if new_w == 0 or new_h == 0:
29
+ new_w, new_h = 768 * 768 # Fallback
30
 
31
  return image.resize((new_w, new_h), Image.LANCZOS)
32