0

Credits to @eprev for this conversion (per image)

$ convert -alpha remove party-never.png pgm: \ | mkbitmap -f 32 -t 0.4 - -o - \ | potrace --svg -o party-never.svg

I would like to have it in Python. Integrate in this code:

from PIL import Image
import os

Image.MAX_IMAGE_PIXELS = None

path = "./*your-source-folder*"

resize_ratio = 2  # where 0.5 is half size, 2 is double size



def resize_aspect_fit():
    dirs = os.listdir(path)
    for item in dirs:
        print(item)
        if item == '.DS_Store':
            continue

        if item == 'Icon\r':
            continue
      
        if item.endswith(".mp4"):
            continue
        
        if item.endswith(".txt"):
            continue
        
        if item.endswith(".db"):
            continue

        if os.path.isfile(path+item):
            image = Image.open(path+item)
            file_path, extension = os.path.splitext(path+item)
            new_image_height = int(image.size[0] / (1/resize_ratio))
            new_image_length = int(image.size[1] / (1/resize_ratio))

            image = image.resize((new_image_height, new_image_length), Image.ANTIALIAS)
            
            image.save("./*your-output-folder*/" + item)


resize_aspect_fit()

I don't know how can I integrate the codes or if its even possible

  • Imagemagick can convert to SVG using potrace. So your could use a subprocess command to call Imagemagick in Python. Or use Python Wand, which uses Imagemagick. – fmw42 Feb 13 '23 at 17:07

0 Answers0