[15] add blur(##) to overlays

pull/858/head
meisnate12 3 years ago
parent a66ccc1a8f
commit ed797dfc81

@ -1 +1 @@
1.16.5-develop14 1.16.5-develop15

@ -307,6 +307,16 @@ class CollectionBuilder:
else: else:
self.overlay = self.mapping_name self.overlay = self.mapping_name
logger.warning(f"{self.Type} Warning: No overlay attribute using mapping name {self.mapping_name} as the overlay name") logger.warning(f"{self.Type} Warning: No overlay attribute using mapping name {self.mapping_name} as the overlay name")
if self.overlay.startswith("blur"):
try:
match = re.search("\\(([^)]+)\\)", self.overlay)
if not match or 0 >= int(match.group(1)) > 100:
raise ValueError
self.overlay = f"blur({match.group(1)})"
except ValueError:
logger.error(f"Overlay Error: failed to parse overlay blur name: {self.overlay} defaulting to blur(50)")
self.overlay = "blur(50)"
overlay_path = os.path.join(library.overlay_folder, f"{self.overlay}.png") overlay_path = os.path.join(library.overlay_folder, f"{self.overlay}.png")
if self.overlay != "blur" and not os.path.exists(overlay_path): if self.overlay != "blur" and not os.path.exists(overlay_path):
raise Failed(f"{self.Type} Error: Overlay Image not found at: {overlay_path}") raise Failed(f"{self.Type} Error: Overlay Image not found at: {overlay_path}")

@ -1,4 +1,4 @@
import os, time import os, re, time
from modules import util from modules import util
from modules.builder import CollectionBuilder from modules.builder import CollectionBuilder
from modules.util import Failed from modules.util import Failed
@ -29,6 +29,7 @@ class Overlays:
logger.separator(f"Removing Overlays for the {self.library.name} Library") logger.separator(f"Removing Overlays for the {self.library.name} Library")
logger.info("") logger.info("")
else: else:
overlay_suppression = {}
for overlay_file in self.library.overlay_files: for overlay_file in self.library.overlay_files:
for k, v in overlay_file.overlays.items(): for k, v in overlay_file.overlays.items():
try: try:
@ -59,13 +60,16 @@ class Overlays:
overlay_to_keys[builder.overlay].append(item.ratingKey) overlay_to_keys[builder.overlay].append(item.ratingKey)
if builder.suppress_overlays: if builder.suppress_overlays:
for rk in overlay_to_keys[builder.overlay]: overlay_suppression[builder.overlay] = builder.suppress_overlays
for suppress_overlay in builder.suppress_overlays:
if suppress_overlay in overlay_to_keys and rk in overlay_to_keys[suppress_overlay]:
overlay_to_keys[suppress_overlay].remove(rk)
except Failed as e: except Failed as e:
logger.error(e) logger.error(e)
for over_name, suppress_names in overlay_suppression.items():
for rk in overlay_to_keys[over_name]:
for suppress_name in suppress_names:
if suppress_name in overlay_to_keys and rk in overlay_to_keys[suppress_name]:
overlay_to_keys[suppress_name].remove(rk)
for overlay_name, over_keys in overlay_to_keys.items(): for overlay_name, over_keys in overlay_to_keys.items():
if overlay_name == "blur": if overlay_name == "blur":
overlay_updated[overlay_name] = False overlay_updated[overlay_name] = False
@ -144,7 +148,7 @@ class Overlays:
logger.info("") logger.info("")
logger.separator(f"Applying Overlays for the {self.library.name} Library") logger.separator(f"Applying Overlays for the {self.library.name} Library")
logger.info("") logger.info("")
for i, (over_key, (item, over_names)) in enumerate(sorted(key_to_overlays.items(), key=lambda io: io[1][0].title), 1): for i, (over_key, (item, over_names)) in enumerate(sorted(key_to_overlays.items(), key=lambda io: io[1][0].titleSort), 1):
try: try:
logger.ghost(f"Overlaying: {i}/{len(key_to_overlays)} {item.title}") logger.ghost(f"Overlaying: {i}/{len(key_to_overlays)} {item.title}")
image_compare = None image_compare = None
@ -210,10 +214,16 @@ class Overlays:
new_poster = Image.open(poster.location if poster else has_original).convert("RGBA") new_poster = Image.open(poster.location if poster else has_original).convert("RGBA")
temp = os.path.join(self.library.overlay_folder, f"temp.png") temp = os.path.join(self.library.overlay_folder, f"temp.png")
try: try:
blur_num = 0
for over_name in over_names: for over_name in over_names:
if over_name == "blur": if over_name.startswith("blur"):
new_poster = new_poster.filter(ImageFilter.GaussianBlur(50)) blur_test = int(re.search("\\(([^)]+)\\)", over_name).group(1))
else: if blur_test > blur_num:
blur_num = blur_test
if blur_num > 0:
new_poster = new_poster.filter(ImageFilter.GaussianBlur(blur_num))
for over_name in over_names:
if not over_name.startswith("blur"):
new_poster = new_poster.resize(overlay_images[over_name].size, Image.ANTIALIAS) new_poster = new_poster.resize(overlay_images[over_name].size, Image.ANTIALIAS)
new_poster.paste(overlay_images[over_name], (0, 0), overlay_images[over_name]) new_poster.paste(overlay_images[over_name], (0, 0), overlay_images[over_name])
new_poster.save(temp, "PNG") new_poster.save(temp, "PNG")

Loading…
Cancel
Save