Skip to content

Commit

Permalink
Increase visibility of error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Sep 23, 2021
1 parent 1ad7cf1 commit b6cc155
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
11 changes: 7 additions & 4 deletions app/models/text.py
Expand Up @@ -34,8 +34,12 @@ def get_preview(cls) -> "Text":
)

@classmethod
def get_watermark(cls, is_preview: bool = False) -> "Text":
return cls(color="red" if is_preview else "#FFFFFF85")
def get_error(cls) -> "Text":
return cls(color="yellow", anchor_x=0.5)

@classmethod
def get_watermark(cls) -> "Text":
return cls(color="#FFFFFF85")

def get_anchor(self, image_size: Dimensions, watermark: str = "") -> Point:
image_width, image_height = image_size
Expand All @@ -49,15 +53,14 @@ def get_size(self, image_size: Dimensions) -> Dimensions:
size = int(image_width * self.scale_x), int(image_height * self.scale_y)
return size

def get_stroke(self, width: int, is_preview: bool = False) -> tuple[int, str]:
def get_stroke(self, width: int) -> tuple[int, str]:
if self.color == "black":
width = 1
color = "#FFFFFF85"
elif "#" in self.color:
width = 1
color = "#000000" + self.color[-2:]
else:
width = 0 if is_preview else width
color = "black"
return width, color

Expand Down
5 changes: 3 additions & 2 deletions app/utils/images.py
Expand Up @@ -318,8 +318,9 @@ def add_watermark(image: Image, text: str, is_preview: bool) -> Image:
font = get_font("tiny", text, 0.0, size, 99)
offset = get_text_offset(text, font, size)

watermark = Text.get_watermark(is_preview)
stroke_width, stroke_fill = watermark.get_stroke(get_stroke_width(font), is_preview)
watermark = Text.get_error() if is_preview else Text.get_watermark()
stroke_width = get_stroke_width(font)
stroke_width, stroke_fill = watermark.get_stroke(stroke_width)

box = Image.new("RGBA", image.size)
draw = ImageDraw.Draw(box)
Expand Down
4 changes: 2 additions & 2 deletions app/views/clients.py
Expand Up @@ -56,7 +56,7 @@ async def preview_image(request, id: str, lines: list[str], style: str):
if not template.image.exists():
logger.error(f"Unable to download image URL: {id}")
template = models.Template.objects.get("_error")
error = "Invalid Background Image"
error = "Invalid Background"
else:
template = models.Template.objects.get_or_none(id)
if not template:
Expand All @@ -67,7 +67,7 @@ async def preview_image(request, id: str, lines: list[str], style: str):
if not utils.urls.schema(style):
style = style.lower()
if not await template.check(style):
error = "Invalid Overlay Image"
error = "Invalid Overlay"

data, content_type = await asyncio.to_thread(
utils.images.preview, template, lines, style=style, watermark=error.upper()
Expand Down

0 comments on commit b6cc155

Please sign in to comment.