From 6a275a6d9a3440f4d12453d28071b72d2ff78788 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Wed, 14 Sep 2022 17:09:57 -0400 Subject: [PATCH] [25] add backdrop overlay --- VERSION | 2 +- docs/metadata/overlay.md | 16 ++++++++++++++++ modules/overlay.py | 19 +++++++++++++++---- modules/overlays.py | 3 +++ 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index 2b413951..138123f2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.17.3-develop24 +1.17.3-develop25 diff --git a/docs/metadata/overlay.md b/docs/metadata/overlay.md index ae211595..b689e42e 100644 --- a/docs/metadata/overlay.md +++ b/docs/metadata/overlay.md @@ -142,6 +142,22 @@ overlays: ![](blur.png) +### Backdrop Overlay + +There is a special overlay named `backdrop` that when given as the overlay name will instead of finding the image will just apply the background instead. + +You can set the size of the backdrop with `back_width` and `back_height`. By Default, they will extend the length of the Image. + +```yaml +overlays: + blur: + overlay: + name: backdrop + back_color: "#00000099" + builder_level: episode + plex_all: true +``` + ### Text Overlay You can add text as an overlay using the special `text()` overlay name. Anything inside the parentheses will be added as an overlay onto the image. Ex `text(4K)` adds `4K` to the image. diff --git a/modules/overlay.py b/modules/overlay.py index acaf837c..1d6b202d 100644 --- a/modules/overlay.py +++ b/modules/overlay.py @@ -132,6 +132,8 @@ class Overlay: self.stroke_width = 0 self.addon_offset = 0 self.addon_position = None + self.back_width = None + self.back_height = None self.special_text = None logger.debug("") @@ -187,14 +189,16 @@ class Overlay: self.back_box = None back_width = util.parse("Overlay", "back_width", self.data["back_width"], datatype="int", parent="overlay", minimum=0) if "back_width" in self.data else -1 back_height = util.parse("Overlay", "back_height", self.data["back_height"], datatype="int", parent="overlay", minimum=0) if "back_height" in self.data else -1 - if (back_width >= 0 > back_height) or (back_height >= 0 > back_width): + if self.name == "backdrop": + self.back_box = (back_width, back_height) + elif (back_width >= 0 > back_height) or (back_height >= 0 > back_width): raise Failed(f"Overlay Error: overlay attributes back_width and back_height must be used together") - if self.back_align != "center" and (back_width < 0 or back_height < 0): + elif self.back_align != "center" and (back_width < 0 or back_height < 0): raise Failed(f"Overlay Error: overlay attribute back_align only works when back_width and back_height are used") elif back_width >= 0 and back_height >= 0: self.back_box = (back_width, back_height) self.has_back = True if self.back_color or self.back_line_color else False - if self.has_back and not self.has_coordinates() and not self.queue: + if self.name != "backdrop" and self.has_back and not self.has_coordinates() and not self.queue: raise Failed(f"Overlay Error: horizontal_offset and vertical_offset are required when using a backdrop") def get_and_save_image(image_url): @@ -216,7 +220,7 @@ class Overlay: time.sleep(1) return image_path - if not self.name.startswith("blur"): + if not self.name.startswith(("blur", "backdrop")): if "file" in self.data and self.data["file"]: self.path = self.data["file"] elif "git" in self.data and self.data["git"]: @@ -310,6 +314,9 @@ class Overlay: box = self.image.size if self.image else None self.portrait, self.portrait_box = self.get_backdrop(portrait_dim, box=box, text=self.name[5:-1]) self.landscape, self.landscape_box = self.get_backdrop(landscape_dim, box=box, text=self.name[5:-1]) + elif self.name.startswith("backdrop"): + self.portrait, self.portrait_box = self.get_backdrop(portrait_dim, box=self.back_box) + self.landscape, self.landscape_box = self.get_backdrop(landscape_dim, box=self.back_box) else: if not self.path: clean_name, _ = util.validate_filename(self.name) @@ -346,6 +353,10 @@ class Overlay: box = (text_width, text_height) box_width, box_height = box back_width, back_height = self.back_box if self.back_box else (None, None) + if back_width == -1: + back_width = canvas_box[0] + if back_height == -1: + back_height = canvas_box[1] start_x, start_y = self.get_coordinates(canvas_box, box, new_cords=new_cords) main_x = start_x main_y = start_y diff --git a/modules/overlays.py b/modules/overlays.py index 48ef1cce..ec164d12 100644 --- a/modules/overlays.py +++ b/modules/overlays.py @@ -301,6 +301,9 @@ class Overlays: new_poster.paste(overlay_image, (0, 0), overlay_image) if current_overlay.image: new_poster.paste(current_overlay.image, addon_box, current_overlay.image) + elif current_overlay.name == "backdrop": + overlay_image = current_overlay.landscape if isinstance(item, Episode) else current_overlay.portrait + new_poster.paste(overlay_image, (0, 0), overlay_image) else: if current_overlay.has_coordinates(): if current_overlay.portrait is not None: