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:
parent
698ad5009a
commit
c92e6aa620
2 changed files with 19 additions and 7 deletions
|
@ -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")
|
||||
|
|
|
@ -5,7 +5,7 @@ Module containing the functions used to generate ``<svg>`` icons from other ``<s
|
|||
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>``.
|
||||
"""
|
||||
|
@ -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("""
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2000 2000">
|
||||
doc = bs4.BeautifulSoup(f"""
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {width} {height}">
|
||||
</svg>
|
||||
""", features="lxml-xml")
|
||||
container: bs4.Tag = doc.svg
|
||||
|
|
Loading…
Reference in a new issue