Skip to content

Commit

Permalink
Merge pull request #8 from LEv145/dev
Browse files Browse the repository at this point in the history
v 2.5
  • Loading branch information
LEv145 authored Aug 5, 2023
2 parents f80fdb3 + d6fc977 commit 44365fa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 35 deletions.
13 changes: 2 additions & 11 deletions src/nodes/grid_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ def execute(
font_size: int,
) -> tuple[Annotation]:
font = ImageFont.truetype(str(STATIC_PATH / "Roboto-Regular.ttf"), size=font_size)
column_texts_list = self._set_value_to_texts_list(
self._get_texts_from_string(column_texts),
)
row_texts_list = self._set_value_to_texts_list(
self._get_texts_from_string(row_texts),
)
column_texts_list = self._get_texts_from_string(column_texts)
row_texts_list = self._get_texts_from_string(row_texts)

result = Annotation(column_texts=column_texts_list, row_texts=row_texts_list, font=font)
return (result,)
Expand All @@ -42,8 +38,3 @@ def _get_texts_from_string(self, string: str) -> list[str]:
for i in string.split(";")
if (result := i.strip()) != ""
]

def _set_value_to_texts_list(self, texts_list: list[str]) -> list[str]:
if not texts_list:
return ["None"]
return texts_list
55 changes: 31 additions & 24 deletions src/utils/images_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,24 @@ def _create_grid_annotation(
row_texts: list[str],
font: ImageFont.FreeTypeFont,
) -> Image.Image:
if not column_texts or not row_texts:
raise ValueError("Column text or row text is empty")
if not column_texts and not row_texts:
raise ValueError("Column text and row text is empty")

grid = grid_info.image
left_padding = int(
max(
font.getlength(splitted_text)
for raw_text in row_texts
for splitted_text in raw_text.split("\n")
left_padding = 0
top_padding = 0

if row_texts:
left_padding = int(
max(
font.getlength(splitted_text)
for raw_text in row_texts
for splitted_text in raw_text.split("\n")
)
+ font.getlength(WIDEST_LETTER)*2
)
+ font.getlength(WIDEST_LETTER)*2
)
top_padding = int(font.size * 2)
if column_texts:
top_padding = int(font.size * 2)

image = Image.new(
"RGB",
Expand All @@ -116,20 +121,22 @@ def _create_grid_annotation(
draw.font = font # type: ignore

_paste_image_to_lower_left_corner(image, grid)
_draw_column_text(
draw=draw,
texts=column_texts,
grid_info=grid_info,
left_padding=left_padding,
top_padding=top_padding,
)
_draw_row_text(
draw=draw,
texts=row_texts,
grid_info=grid_info,
left_padding=left_padding,
top_padding=top_padding,
)
if column_texts:
_draw_column_text(
draw=draw,
texts=column_texts,
grid_info=grid_info,
left_padding=left_padding,
top_padding=top_padding,
)
if row_texts:
_draw_row_text(
draw=draw,
texts=row_texts,
grid_info=grid_info,
left_padding=left_padding,
top_padding=top_padding,
)

return image

Expand Down

0 comments on commit 44365fa

Please sign in to comment.