From f8518e7b462a049eba25b5fb0c57abf450a1174d Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Fri, 3 Jun 2022 09:08:19 -0400 Subject: [PATCH] [19] overlay text fix --- VERSION | 2 +- modules/overlays.py | 2 +- modules/util.py | 40 +++++----------------------------------- 3 files changed, 7 insertions(+), 37 deletions(-) diff --git a/VERSION b/VERSION index 7b33e1b7..90c5137a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.17.0-develop18 +1.17.0-develop19 diff --git a/modules/overlays.py b/modules/overlays.py index c2614ede..9fb80702 100644 --- a/modules/overlays.py +++ b/modules/overlays.py @@ -200,7 +200,7 @@ class Overlays: text = f"{int(text * 10)}%" if flat and str(text).endswith(".0"): text = str(text)[:-2] - overlay_image = overlay.get_overlay_image(str(text), (canvas_width, canvas_height)) + overlay_image = overlay.get_backdrop((canvas_width, canvas_height), text=str(text)) else: overlay_image = overlay.landscape if isinstance(item, Episode) else overlay.portrait new_poster.paste(overlay_image, (0, 0), overlay_image) diff --git a/modules/util.py b/modules/util.py index 64fa6044..fdcc002c 100644 --- a/modules/util.py +++ b/modules/util.py @@ -1013,8 +1013,8 @@ class Overlay: raise Failed(f"Overlay Error: overlay font_color: {self.data['font_color']} invalid") text = self.name[5:-1] if text not in [f"{a}{s}" for a in ["audience_rating", "critic_rating", "user_rating"] for s in ["", "%"]]: - self.portrait = self.get_backdrop(text, portrait_dim) - self.landscape = self.get_backdrop(text, landscape_dim) + self.portrait = self.get_backdrop(portrait_dim, text=text) + self.landscape = self.get_backdrop(landscape_dim, text=text) else: if "|" in self.name: raise Failed(f"Overlay Error: Overlay Name: {self.name} cannot contain '|'") @@ -1031,14 +1031,14 @@ class Overlay: try: self.image = Image.open(self.path).convert("RGBA") if self.has_coordinates(): - self.portrait, self.portrait_box = self.get_backdrop(portrait_dim, self.image.size) - self.landscape, self.landscape_box = self.get_backdrop(landscape_dim, self.image.size) + self.portrait, self.portrait_box = self.get_backdrop(portrait_dim, box=self.image.size) + self.landscape, self.landscape_box = self.get_backdrop(landscape_dim, box=self.image.size) if self.config.Cache: self.config.Cache.update_image_map(self.name, f"{self.library.image_table_name}_overlays", self.name, overlay_size) except OSError: raise Failed(f"Overlay Error: overlay image {self.path} failed to load") - def get_backdrop(self, canvas_box, box, text=None): + def get_backdrop(self, canvas_box, box=None, text=None): overlay_image = None if text is not None: _, _, width, height = self.get_text_size(text) @@ -1067,36 +1067,6 @@ class Overlay: drawing.text((x_cord, y_cord), text, font=self.font, fill=self.font_color, anchor="lt") return overlay_image, (x_cord, y_cord) - def get_overlay_image(self, text, canvas_box): - overlay_image = Image.new("RGBA", canvas_box, (255, 255, 255, 0)) - drawing = ImageDraw.Draw(overlay_image) - if isinstance(text, str): - _, _, width, height = self.get_text_size(text) - box = (width, height) - else: - box = text.size - x_cord, y_cord = self.get_coordinates(canvas_box, box) - if self.back_color or self.back_line_color: - cords = ( - x_cord - self.back_padding, - y_cord - self.back_padding, - x_cord + (self.back_box[0] if self.back_box else box[0]) + self.back_padding, - y_cord + (self.back_box[1] if self.back_box else box[1]) + self.back_padding - ) - if self.back_box: - x_cord = x_cord + (self.back_box[0] - box[0]) // 2 - y_cord = y_cord + (self.back_box[1] - box[1]) // 2 - - if self.back_radius: - drawing.rounded_rectangle(cords, fill=self.back_color, outline=self.back_line_color, width=self.back_line_width, radius=self.back_radius) - else: - drawing.rectangle(cords, fill=self.back_color, outline=self.back_line_color, width=self.back_line_width) - if isinstance(text, str): - drawing.text((x_cord, y_cord), text, font=self.font, fill=self.font_color, anchor="lt") - else: - overlay_image.paste(text, (x_cord, y_cord), text) - return overlay_image - def get_overlay_compare(self): output = self.name if self.group: