-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajoute la génération des smileys au format PNG depuis le SVG
- Loading branch information
Showing
6 changed files
with
296 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import argparse | ||
import pathlib | ||
import os | ||
|
||
import cairosvg | ||
|
||
|
||
def convert_folder_to_svg(src_folder: pathlib.Path, dst_folder: pathlib.Path) -> int: | ||
""" | ||
Convert all SVGs from src_folder into PNGs and write them in dst_folder. | ||
Create dst_folder if needed. | ||
Existing files in dst_fodler are overwritten. | ||
Return the number of converted files. | ||
""" | ||
src_files = src_folder.rglob("*.svg") | ||
os.makedirs(dst_folder, exist_ok=True) | ||
converted_file_count = 0 | ||
for src_file in src_files: | ||
dst_file = dst_folder / f"{src_file.stem}.png" | ||
cairosvg.svg2png(url=src_file.as_posix(), write_to=dst_file.as_posix()) | ||
converted_file_count += 1 | ||
return converted_file_count | ||
|
||
|
||
def get_cli_args(): | ||
"""Get arguments from the CLI.""" | ||
|
||
# Build parser | ||
parser = argparse.ArgumentParser(description="Convert a folder of SVG files to PNG") | ||
parser.add_argument("source", help="Folder containing the SVG files to be converted") | ||
parser.add_argument("destination", help="Folder in which the PNG files are written") | ||
|
||
# Parse | ||
raw_args = parser.parse_args() | ||
processed_args = { | ||
"source": pathlib.Path(raw_args.source), | ||
"destination": pathlib.Path(raw_args.destination), | ||
} | ||
|
||
return processed_args | ||
|
||
|
||
if __name__ == "__main__": | ||
args = get_cli_args() | ||
file_count = convert_folder_to_svg(args["source"], args["destination"]) | ||
print(f"{__file__}: {file_count} files converted.") |
Oops, something went wrong.