[22] add stroke_width and stroke_color to text overlays

This commit is contained in:
meisnate12 2022-09-14 11:27:22 -04:00
parent bc0da63607
commit bb878df032
3 changed files with 16 additions and 4 deletions

View file

@ -1 +1 @@
1.17.3-develop21
1.17.3-develop22

View file

@ -85,6 +85,8 @@ There are many attributes available when using overlays to edit how they work.
| `font_style` | Font style for Variable Fonts. Only needed when using a Variable Font.<br>**Value:** Variable Font Style | &#10060; |
| `font_size` | Font Size for the Text Overlay.<br>**Value:** Integer greater than 0 | &#10060; |
| `font_color` | Font Color for the Text Overlay.<br>**Value:** Color Hex Code in format `#RGB`, `#RGBA`, `#RRGGBB` or `#RRGGBBAA`. | &#10060; |
| `stroke_width` | Font Stroke Width for the Text Overlay.<br>**Value:** Integer greater than 0 | &#10060; |
| `stroke_color` | Font Stroke Color for the Text Overlay.<br>**Value:** Color Hex Code in format `#RGB`, `#RGBA`, `#RRGGBB` or `#RRGGBBAA`. | &#10060; |
| `back_color` | Backdrop Color for the Text Overlay.<br>**Value:** Color Hex Code in format `#RGB`, `#RGBA`, `#RRGGBB` or `#RRGGBBAA`. | &#10060; |
| `back_width` | Backdrop Width for the Text Overlay. If `back_width` is not specified the Backdrop Sizes to the text<br>**`back_height` is required when using `back_width`**<br>**Value:** Integer greater than 0 | &#10060; |
| `back_height` | Backdrop Height for the Text Overlay. If `back_height` is not specified the Backdrop Sizes to the text<br>**`back_width` is required when using `back_height`**<br>**Value:** Integer greater than 0 | &#10060; |

View file

@ -128,6 +128,8 @@ class Overlay:
self.font_name = None
self.font_size = 36
self.font_color = None
self.stroke_color = None
self.stroke_width = 0
self.addon_offset = 0
self.addon_position = None
self.special_text = None
@ -279,12 +281,18 @@ class Overlay:
raise Failed(f"Overlay Error: Font Style {self.data['font_style']} not found. Options: {','.join(variation_names)}")
except OSError:
logger.warning(f"Overlay Warning: font: {self.font} does not have variations")
self.font_color = None
if "font_color" in self.data and self.data["font_color"]:
try:
self.font_color = ImageColor.getcolor(self.data["font_color"], "RGBA")
except ValueError:
raise Failed(f"Overlay Error: overlay font_color: {self.data['font_color']} invalid")
if "stroke_size" in self.data:
self.stroke_size = util.parse("Overlay", "stroke_size", self.data["stroke_size"], datatype="int", parent="overlay", default=self.stroke_size)
if "stroke_color" in self.data and self.data["stroke_color"]:
try:
self.stroke_color = ImageColor.getcolor(self.data["stroke_color"], "RGBA")
except ValueError:
raise Failed(f"Overlay Error: overlay stroke_color: {self.data['stroke_color']} invalid")
if text in old_special_text:
text_mod = text[-1] if text[-1] in ["0", "%", "#"] else None
text = text if text_mod is None else text[:-1]
@ -416,7 +424,8 @@ class Overlay:
addon_y = main_y + ((text_height - image_height) / 2)
if text is not None:
drawing.text((int(main_x), int(main_y)), text, font=self.font, fill=self.font_color, anchor="lt")
drawing.text((int(main_x), int(main_y)), text, font=self.font, fill=self.font_color,
stroke_fill=self.stroke_color, stroke_width=self.stroke_width, anchor="lt")
if addon_x is not None:
main_x = addon_x
main_y = addon_y
@ -434,7 +443,8 @@ class Overlay:
output += f"{self.back_box[0]}{self.back_box[1]}{self.back_align}"
if self.addon_position is not None:
output += f"{self.addon_position}{self.addon_offset}"
for value in [self.font_color, self.back_color, self.back_radius, self.back_padding, self.back_line_color, self.back_line_width]:
for value in [self.font_color, self.back_color, self.back_radius, self.back_padding,
self.back_line_color, self.back_line_width, self.stroke_color, self.stroke_width]:
if value is not None:
output += f"{value}"
return output