From c92e6aa620407ed514834dfa84409ce3a0b655f1 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 7 Apr 2023 21:22:17 +0200 Subject: [PATCH] Add `--width` and `--height` options --- emblematic/__main__.py | 18 +++++++++++++++--- emblematic/compose.py | 8 ++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/emblematic/__main__.py b/emblematic/__main__.py index 5a78c5c..4f85599 100644 --- a/emblematic/__main__.py +++ b/emblematic/__main__.py @@ -36,13 +36,25 @@ def main(): "-f", "--fill", "icon_fill", type=str, required=True, - help="The color to fill icons with." + help="The color to fill icons with.", ) @click.option( "-o", "--output-dir", "output_dir", type=click.Path(exists=True, file_okay=False, dir_okay=True), required=True, - help="The directory where output files should be placed in." + help="The directory where output files should be placed in.", +) +@click.option( + "-w", "--width", "width", + type=int, + default=2000, + help="The width the output files should have.", +) +@click.option( + "-h", "--height", "height", + type=int, + default=2000, + help="The height the output files should have." ) def basic(bg_file, icon_paths, icon_fill, output_dir): icon_paths = map(pathlib.Path, icon_paths) @@ -65,7 +77,7 @@ def basic(bg_file, icon_paths, icon_fill, output_dir): icon.path.attrs["fill"] = icon_fill click.echo(" → ", nl=False) - svg_doc = compose_basic(background=bg, icon=icon) + svg_doc = compose_basic(background=bg, icon=icon, width=width, height=height) click.echo(" → ", nl=False) svg_bytes = bytes(svg_doc.prettify(), encoding="utf8") diff --git a/emblematic/compose.py b/emblematic/compose.py index 5a35062..a0d0ca2 100644 --- a/emblematic/compose.py +++ b/emblematic/compose.py @@ -5,7 +5,7 @@ Module containing the functions used to generate ```` icons from other `` bs4.Tag: +def compose_basic(background: bs4.Tag, icon: bs4.Tag, width: int, height: int) -> bs4.Tag: """ Create a new and nice ```` icon from the given background ```` and the given foreground ````. """ @@ -25,10 +25,10 @@ def compose_basic(background: bs4.Tag, icon: bs4.Tag) -> bs4.Tag: icon.attrs["width"] = "63%" icon.attrs["height"] = "63%" icon.attrs["preserveAspectRatio"] = "xMidYMid meet" - icon.attrs["transform"] = "translate(370, 370)" + icon.attrs["transform"] = f"translate({width * 0.37}, {height * 0.37})" - doc = bs4.BeautifulSoup(""" - + doc = bs4.BeautifulSoup(f""" + """, features="lxml-xml") container: bs4.Tag = doc.svg