From a8f4125fad73d5a0351e27d22ffdda81347382e7 Mon Sep 17 00:00:00 2001 From: Bipin Date: Sun, 24 Mar 2024 13:58:09 +0530 Subject: [PATCH 1/4] add custom color option --- .gitignore | 3 ++- signwriting/visualizer/visualize.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index f00ec3e..7e67494 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ build/ -signwriting.egg-info/ \ No newline at end of file +signwriting.egg-info/ +__pycache__/ \ No newline at end of file diff --git a/signwriting/visualizer/visualize.py b/signwriting/visualizer/visualize.py index 2428fc0..3c52f41 100644 --- a/signwriting/visualizer/visualize.py +++ b/signwriting/visualizer/visualize.py @@ -21,7 +21,7 @@ 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, fill_color=(255, 255, 255), line_color=(0, 0, 0)) -> Image: sign = fsw_to_sign(fsw) if len(sign['symbols']) == 0: return Image.new('RGBA', (1, 1), (0, 0, 0, 0)) @@ -52,7 +52,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), font=fill_font, fill=fill_color) + draw.text((x, y), symbol_line(symbol_id), font=line_font, fill=line_color) return img From e0c4f1c7c7ee32a322f74ee2564160e17843f917 Mon Sep 17 00:00:00 2001 From: Bipin Date: Sun, 24 Mar 2024 14:20:41 +0530 Subject: [PATCH 2/4] small fix --- signwriting/visualizer/visualize.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/signwriting/visualizer/visualize.py b/signwriting/visualizer/visualize.py index 3c52f41..45e3995 100644 --- a/signwriting/visualizer/visualize.py +++ b/signwriting/visualizer/visualize.py @@ -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, fill_color=(255, 255, 255), line_color=(0, 0, 0)) -> Image: +def signwriting_to_image(fsw: str, antialiasing=True, trust_box=True, fill_color: tuple[int, int , int, int]=(255, 255, 255, 255), + 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)) @@ -41,7 +42,7 @@ def signwriting_to_image(fsw: str, antialiasing=True, trust_box=True, fill_color 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' @@ -52,7 +53,7 @@ def signwriting_to_image(fsw: str, antialiasing=True, trust_box=True, fill_color 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=fill_color) - draw.text((x, y), symbol_line(symbol_id), font=line_font, fill=line_color) + draw.text((x, y), symbol_fill(symbol_id), font=fill_font, fill=fill_color, embedded_color=embedded_color) + draw.text((x, y), symbol_line(symbol_id), font=line_font, fill=line_color, embedded_color=embedded_color) return img From e222aa15d568c6f054753056a1057676275f8fde Mon Sep 17 00:00:00 2001 From: Bipin Date: Sun, 24 Mar 2024 14:31:59 +0530 Subject: [PATCH 3/4] lint fix --- signwriting/visualizer/visualize.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/signwriting/visualizer/visualize.py b/signwriting/visualizer/visualize.py index 45e3995..c7c4dd3 100644 --- a/signwriting/visualizer/visualize.py +++ b/signwriting/visualizer/visualize.py @@ -21,7 +21,7 @@ def get_symbol_size(symbol: str): # pylint: disable=too-many-locals -def signwriting_to_image(fsw: str, antialiasing=True, trust_box=True, fill_color: tuple[int, int , int, int]=(255, 255, 255, 255), +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: @@ -53,7 +53,7 @@ def signwriting_to_image(fsw: str, antialiasing=True, trust_box=True, fill_color 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=fill_color, embedded_color=embedded_color) - draw.text((x, y), symbol_line(symbol_id), font=line_font, fill=line_color, embedded_color=embedded_color) + 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 From 0689ecfdc7a6615602e599f461fc09a7327dbf9e Mon Sep 17 00:00:00 2001 From: Bipin Date: Mon, 25 Mar 2024 12:06:55 +0530 Subject: [PATCH 4/4] test case for custom colors --- .../M518x518S30a00482x483S33e00482x483.png | Bin 0 -> 2151 bytes signwriting/visualizer/test_visualize.py | 11 +++++++++++ 2 files changed, 11 insertions(+) create mode 100644 signwriting/visualizer/test_assets/M518x518S30a00482x483S33e00482x483.png diff --git a/signwriting/visualizer/test_assets/M518x518S30a00482x483S33e00482x483.png b/signwriting/visualizer/test_assets/M518x518S30a00482x483S33e00482x483.png new file mode 100644 index 0000000000000000000000000000000000000000..5644b00e37ebeac534851fba981032c961f6ea08 GIT binary patch literal 2151 zcmV-t2$=VYP)4 z(V(U-RS_de9|&edL0~{Z_H97+ZDbgj{mt8M|7gZD;EaOy9KUn!AMbw4{k{9{yWjmT zh7f|`NJ~-A{K^}xA8XY5Y1V#f6w7cz#33GFfN&gRc|x4@^7Cj79Ot8&vSRcS#-GkDR4BH+#R(gKu;b3;OtOI0+aa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ZF0030qZ2#zG0XR%V_0-6`)3t|bE92?PrtHV&KQI*Q9uO%l0D%9k?$_o7CL;v+t)mr*t{e+5)E_9l z-n6aYochb5z#tCslt;=>7bQR3(^l3y*OlG9iw%DQ0C;=Lgijv>&D}g<6VAiv`kc;H zhHgukGsiifMQ#rqCsp0M)bPimD-ZWR4aR0>yorOw-#4l>OC~LOHDUA{{{M0Hl9qm( zzcj?N_HjY!csx+Z2y`a)R+Fo|WV6s-sr&DxDP#mn`COINQrt6-CK-`qGA+LPaM#cI z5#3Fy`Kzn^Wq4!_iJPCs#L3fGU8^y|-anuWI{!&dm9E7Y86F*wy7<8B%bkAR>o3p7hQDs(YMjWrYjU|yp{ ztzk3#(n6<=%D{P;(}I#B8PD_UvujLRGT3j7q-6E6*;5_$PZWyA9x~+I`a5-ujTHq% z_!O@C$D1)PS|r+~r_nGuWv42evM>^9h-d8wr{+Wf4g*dQPAgZFmJGW1X-+w5q701WX2809VzYNf&Ay097kY2z1! dBn|h6_%F^px``FtiTD5j002ovPDHLkV1hhT9o+x` literal 0 HcmV?d00001 diff --git a/signwriting/visualizer/test_visualize.py b/signwriting/visualizer/test_visualize.py index 7d27d44..630fa68 100644 --- a/signwriting/visualizer/test_visualize.py +++ b/signwriting/visualizer/test_visualize.py @@ -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()