Advertisement
here2share

# fn_resize.py

Sep 19th, 2023
719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. # fn_resize.py
  2.  
  3. def resize(x, y, area, new_area):
  4.     ratio = (new_area / area) ** 0.5
  5.     w_new = int(x * ratio)
  6.     h_new = int(y * ratio)
  7.     if w_new > h_new:
  8.         while (w_new + 1) * h_new < new_area:
  9.             w_new += 1
  10.     else:
  11.         while w_new * (h_new + 1) < new_area:
  12.             h_new += 1
  13.     return w_new, h_new, [w_new * h_new]
  14.  
  15. print(resize(3000, 2000, 6000000, 240000))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement