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

Loading…
Cancel
Save