From fe6a5247bcf9ea11af5cf73cf65970206d40226e Mon Sep 17 00:00:00 2001 From: jlw4049 Date: Mon, 29 Jan 2024 22:34:20 -0500 Subject: [PATCH] feat: added a work around to attempt to position text to the top right of the image for different fonts/sizes dynamically, while not 100% accurate it's close enough --- frame_forge/font_scaler.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 frame_forge/font_scaler.py diff --git a/frame_forge/font_scaler.py b/frame_forge/font_scaler.py new file mode 100644 index 0000000..24b832b --- /dev/null +++ b/frame_forge/font_scaler.py @@ -0,0 +1,25 @@ +import math + + +class FontScaler: + def __init__(self, original_font_size=100, original_scale=3.5): + self.original_font_size = original_font_size + self.original_scale = original_scale + + def calculate_scale_factor(self, desired_font_size): + """Calculate the scale factor based on the desired font size.""" + return math.log(desired_font_size) / math.log(self.original_font_size) + + def adjust_scale_factor(self, scale_factor, multiplier): + """Adjust the scale factor with a multiplier.""" + return scale_factor * multiplier + + def scale_font(self, scale_factor): + """Scale the font size based on the original scale and scale factor.""" + return self.original_scale * scale_factor + + def get_adjusted_scale(self, desired_font_size, multiplier=1.0): + """Get the adjusted font scale based on the desired font size and multiplier.""" + scale_factor = self.calculate_scale_factor(desired_font_size) + adjusted_scale_factor = self.adjust_scale_factor(scale_factor, multiplier) + return self.scale_font(adjusted_scale_factor)