Created
September 4, 2025 10:53
-
-
Save kaenova/beb0b6a49387b4172b7f3613c7cbc2f0 to your computer and use it in GitHub Desktop.
like the file name....
This file contains hidden or 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
| import os | |
| os.environ['PATH'] += os.pathsep + os.pathsep.join(["C:\\Program Files\\UniConvertor-2.0rc5\\dlls", "C:\\Program Files\\UniConvertor-2.0rc5\\bin"]) | |
| import cairosvg | |
| # Root directory where your folders are located | |
| ROOT_DIR = r"." | |
| # Target size and DPI | |
| WIDTH, HEIGHT, DPI = 1080, 1080, 300 | |
| def convert_svg_to_png(svg_path, png_path): | |
| try: | |
| cairosvg.svg2png( | |
| url=svg_path, | |
| write_to=png_path, | |
| output_width=WIDTH, | |
| output_height=HEIGHT, | |
| dpi=DPI | |
| ) | |
| print(f"✅ Converted: {svg_path} -> {png_path}") | |
| except Exception as e: | |
| print(f"❌ Failed to convert {svg_path}: {e}") | |
| def process_folders(root_dir): | |
| out_root = os.path.join(root_dir, "@Out") | |
| for subdir, _, files in os.walk(root_dir): | |
| if subdir in ["@Out", ".venv", "__pycache__"]: | |
| continue # skip output folder to avoid recursion | |
| for file in files: | |
| if file.lower().endswith(".svg"): | |
| print(f"Processing: {file}") | |
| svg_path = os.path.join(subdir, file) | |
| # Get relative path of the current subdir from root | |
| rel_path = os.path.relpath(subdir, root_dir) | |
| # Build target folder inside @Out | |
| out_dir = os.path.join(out_root, rel_path) | |
| os.makedirs(out_dir, exist_ok=True) | |
| # Save PNG with same filename | |
| png_path = os.path.join(out_dir, os.path.splitext(file)[0] + ".png") | |
| convert_svg_to_png(svg_path, png_path) | |
| print(f"Saved to: {png_path}\n") | |
| if __name__ == "__main__": | |
| process_folders(ROOT_DIR) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment