Skip to content

Commit

Permalink
Merge pull request #5 from bipinkrish/main
Browse files Browse the repository at this point in the history
Add Customizations
  • Loading branch information
AmitMY authored Mar 25, 2024
2 parents 77816fe + 0689ecf commit 6ce98fe
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
build/
signwriting.egg-info/
signwriting.egg-info/
__pycache__/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions signwriting/visualizer/test_visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ def test_image_small_box_is_corrected(self):

assert_array_equal(np.array(image), np.array(reference_image))

def test_image_with_line_and_embedded_color(self):
fsw = "M518x518S30a00482x483S33e00482x483"

image = signwriting_to_image("M518x518S30a00482x483S33e00482x483",
line_color=(144, 70, 180, 255), embedded_color=True)

assets_path = Path(__file__).parent / "test_assets" / f"{fsw}.png"
reference_image = Image.open(assets_path)

assert_array_equal(np.array(image), np.array(reference_image))


if __name__ == '__main__':
unittest.main()
9 changes: 5 additions & 4 deletions signwriting/visualizer/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def get_symbol_size(symbol: str):


# pylint: disable=too-many-locals
def signwriting_to_image(fsw: str, antialiasing=True, trust_box=True) -> Image:
def signwriting_to_image(fsw: str, antialiasing=True, trust_box=True,
line_color: tuple[int, int , int, int]=(0, 0, 0, 255), embedded_color=False) -> Image:
sign = fsw_to_sign(fsw)
if len(sign['symbols']) == 0:
return Image.new('RGBA', (1, 1), (0, 0, 0, 0))
Expand All @@ -41,7 +42,7 @@ def signwriting_to_image(fsw: str, antialiasing=True, trust_box=True) -> Image:
max_y = max(max_y, symbol_y + symbol_height)

img = Image.new('RGBA', (max_x - min_x, max_y - min_y), (255, 255, 255, 0))
draw = ImageDraw.Draw(img)
draw = ImageDraw.Draw(img, 'RGBA')
if not antialiasing:
draw.fontmode = '1'

Expand All @@ -52,7 +53,7 @@ def signwriting_to_image(fsw: str, antialiasing=True, trust_box=True) -> Image:
x, y = symbol["position"]
x, y = x - min_x, y - min_y
symbol_id = key2id(symbol["symbol"])
draw.text((x, y), symbol_fill(symbol_id), font=fill_font, fill=(255, 255, 255))
draw.text((x, y), symbol_line(symbol_id), font=line_font, fill=(0, 0, 0))
draw.text((x, y), symbol_fill(symbol_id), (255, 255, 255, 255), fill_font)
draw.text((x, y), symbol_line(symbol_id), line_color, line_font, embedded_color=embedded_color)

return img

0 comments on commit 6ce98fe

Please sign in to comment.