MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / scale_to_target_area

Function scale_to_target_area

utils/wei_utils.py:989–1017  ·  view source on GitHub ↗

Scale the given width and height by the same factor to achieve a new area equal to target_width * target_height while preserving the aspect ratio. Parameters: width (float or int): The original width. height (float or int): The original height. target_width (int, opt

(width, height, target_width=900, target_height=1200)

Source from the content-addressed store, hash-verified

987 bullet_content_item[i]['runs'][0]['fill_color'] = fill_color
988
989def scale_to_target_area(width, height, target_width=900, target_height=1200):
990 """
991 Scale the given width and height by the same factor to achieve a new area equal
992 to target_width * target_height while preserving the aspect ratio.
993
994 Parameters:
995 width (float or int): The original width.
996 height (float or int): The original height.
997 target_width (int, optional): The target width for area calculation. Default is 900.
998 target_height (int, optional): The target height for area calculation. Default is 1200.
999
1000 Returns:
1001 tuple: (new_width, new_height) after scaling such that the area is target_width * target_height.
1002 """
1003 # Calculate target area from provided dimensions.
1004 target_area = target_width * target_height
1005
1006 # Calculate original area
1007 current_area = width * height
1008
1009 # Compute scale factor required: s^2 * (width * height) = target_area => s = sqrt(target_area / (width * height))
1010 scale_factor = math.sqrt(target_area / current_area)
1011
1012 # Calculate new dimensions
1013 new_width = width * scale_factor
1014 new_height = height * scale_factor
1015
1016 # Optional: Round the dimensions to integers.
1017 return int(round(new_width)), int(round(new_height))
1018
1019def char_capacity(
1020 bbox,

Callers 1

new_pipeline.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected