Batch converstion from Png to SVG

49 views Asked by At

I need to batch convert Png files into SVG vectorized and traced files.

I need to transform 51.587 png files into svg.

Those files contained in 61115 subfolders, in a folder called "Folder1". The logos are simple to convert as they are 1-4 colors per png.

I tried python scripts with potrace and cairosvg however they don't seem to work as I was able to create svg files with the same name but they were empty or didn't work.

I just need a python code that is able to tranform easy logo pngs into svg files without embedding the raster pixels but vectorizing it making it smooth and lossless via scaling, maintaining the colors, the transparency and name of the png file.

I have a very very limited code knowledge.

I tried python scripts with potrace and cairosvg however they don't seem to work as I was able to create svg files with the same name but they were empty.

from pathlib import Path
import vtracer

# Set the path to the folder where your PNG files are
input_folder = r'C:\Users\utente\desktop\prova - copia - 
copia'

# Set the path to the folder where you want to save the SVG 
files
output_folder = r'C:\Users\utente\desktop\cestino1'

# Iterate over all PNG files in the input folder and its 
subfolders
    for image in Path(input_folder).glob("**/*.png"):
    print(f"Processing {image}")

    # Create the path for the SVG file
    svg_file = Path(output_folder) / 
    image.with_suffix(".svg").name

    # Convert the PNG file to SVG
    vtracer.convert_image_to_svg_py(str(image), 
str(svg_file))
0

There are 0 answers