Skip to content

Commit

Permalink
fill color customization
Browse files Browse the repository at this point in the history
  • Loading branch information
bipinkrish committed Apr 8, 2024
1 parent 0689ecf commit b64d0ba
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.8'

- name: Install Requirements
run: pip install .[dev]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.8'

- name: Install Requirements
run: pip install .[dev]
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 3 additions & 5 deletions signwriting/visualizer/test_visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def test_image_small_box(self):

def test_image_small_box_is_corrected(self):
fsw = "M500x500S2ff00407x501S1ce20436x535S2e300413x552S22b04418x565S36520420x523"

image = signwriting_to_image(fsw, trust_box=False)

assets_path = Path(__file__).parent / "test_assets" / f"{fsw}.png"
Expand All @@ -55,10 +54,9 @@ 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)
fsw = "M530x518S19a30500x482S19a38465x481S22f04509x506S22f14467x504"
image = signwriting_to_image(fsw, line_color=(
10, 23, 122, 255), fill_color=(255, 255, 255, 0))

assets_path = Path(__file__).parent / "test_assets" / f"{fsw}.png"
reference_image = Image.open(assets_path)
Expand Down
10 changes: 6 additions & 4 deletions signwriting/visualizer/visualize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from functools import lru_cache
from pathlib import Path
from typing import Tuple

from PIL import Image, ImageDraw, ImageFont

Expand All @@ -20,9 +21,10 @@ def get_symbol_size(symbol: str):
return right - left, bottom - top


# pylint: disable=too-many-locals
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:
# pylint: disable=too-many-locals, too-many-arguments
def signwriting_to_image(fsw: str, antialiasing=True, trust_box=True, embedded_color=False,
line_color: Tuple[int, int, int, int] = (0, 0, 0, 255),
fill_color: Tuple[int, int, int, int] = (255, 255, 255, 255)) -> Image:
sign = fsw_to_sign(fsw)
if len(sign['symbols']) == 0:
return Image.new('RGBA', (1, 1), (0, 0, 0, 0))
Expand Down Expand Up @@ -53,7 +55,7 @@ def signwriting_to_image(fsw: str, antialiasing=True, trust_box=True,
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), (255, 255, 255, 255), fill_font)
draw.text((x, y), symbol_fill(symbol_id), fill_color, fill_font, embedded_color=embedded_color)
draw.text((x, y), symbol_line(symbol_id), line_color, line_font, embedded_color=embedded_color)

return img

0 comments on commit b64d0ba

Please sign in to comment.