1
Fork 0
mirror of https://github.com/Steffo99/emblematic.git synced 2024-11-22 06:44:19 +00:00

Add --width and --height options

This commit is contained in:
Steffo 2023-04-07 21:22:17 +02:00
parent 698ad5009a
commit c92e6aa620
Signed by: steffo
GPG key ID: 2A24051445686895
2 changed files with 19 additions and 7 deletions

View file

@ -36,13 +36,25 @@ def main():
"-f", "--fill", "icon_fill", "-f", "--fill", "icon_fill",
type=str, type=str,
required=True, required=True,
help="The color to fill icons with." help="The color to fill icons with.",
) )
@click.option( @click.option(
"-o", "--output-dir", "output_dir", "-o", "--output-dir", "output_dir",
type=click.Path(exists=True, file_okay=False, dir_okay=True), type=click.Path(exists=True, file_okay=False, dir_okay=True),
required=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): def basic(bg_file, icon_paths, icon_fill, output_dir):
icon_paths = map(pathlib.Path, icon_paths) 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 icon.path.attrs["fill"] = icon_fill
click.echo("", nl=False) 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) click.echo("", nl=False)
svg_bytes = bytes(svg_doc.prettify(), encoding="utf8") svg_bytes = bytes(svg_doc.prettify(), encoding="utf8")

View file

@ -5,7 +5,7 @@ Module containing the functions used to generate ``<svg>`` icons from other ``<s
import bs4 import bs4
def compose_basic(background: bs4.Tag, icon: bs4.Tag) -> bs4.Tag: def compose_basic(background: bs4.Tag, icon: bs4.Tag, width: int, height: int) -> bs4.Tag:
""" """
Create a new and nice ``<svg>`` icon from the given background ``<svg>`` and the given foreground ``<svg>``. Create a new and nice ``<svg>`` icon from the given background ``<svg>`` and the given foreground ``<svg>``.
""" """
@ -25,10 +25,10 @@ def compose_basic(background: bs4.Tag, icon: bs4.Tag) -> bs4.Tag:
icon.attrs["width"] = "63%" icon.attrs["width"] = "63%"
icon.attrs["height"] = "63%" icon.attrs["height"] = "63%"
icon.attrs["preserveAspectRatio"] = "xMidYMid meet" 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"""
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2000 2000"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {width} {height}">
</svg> </svg>
""", features="lxml-xml") """, features="lxml-xml")
container: bs4.Tag = doc.svg container: bs4.Tag = doc.svg