Skip to content

Commit

Permalink
fixed common resolution issue
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaraStrawberry committed Apr 21, 2023
1 parent 1c97cb4 commit e122f4d
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions scripts/Berry_Method.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,26 @@ def blend_images(img1, img2, alpha=0.5):
return blended

def resize_to_nearest_multiple(width, height, a):
def nearest_multiple(n, a, b):
multiple_a = round(n / a) * a
multiple_b = round(n / b) * b
return min(multiple_a, multiple_b, key=lambda x: abs(x - n))
def nearest_common_multiple(target, a, b):
multiple = 1
nearest_multiple = 0
min_diff = float('inf')

while True:
current_multiple = a * multiple
if current_multiple % b == 0:
diff = abs(target - current_multiple)
if diff < min_diff:
min_diff = diff
nearest_multiple = current_multiple
else:
break
multiple += 1

return nearest_multiple

new_width = nearest_multiple(width, a, 8)
new_height = nearest_multiple(height, a, 8)
new_width = nearest_common_multiple(width, a, 8)
new_height = nearest_common_multiple(height, a, 8)
return int(new_width), int(new_height)

def resize_to_nearest_multiple_of_8(width, height):
Expand Down

0 comments on commit e122f4d

Please sign in to comment.