from flask import Flask, request, jsonify, send_file from flask_cors import CORS from PIL import Image import vtracer import io import os import logging app = Flask(__name__) CORS(app, resources={r"/convert-to-vector": {"origins": "*"}}) # Configure logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') def convert_to_vector(image): input_path = "temp_input.png" # Use .png to support PNG inputs output_svg_path = "temp_output.svg" try: # Save the input image app.logger.debug(f"Saving input image to {input_path}") image.save(input_path) # Convert to SVG using VTracer app.logger.debug("Converting image to SVG") vtracer.convert_image_to_svg_py( input_path, output_svg_path, colormode="color", hierarchical="stacked", mode="spline", filter_speckle=4, color_precision=6, layer_difference=16, corner_threshold=60, length_threshold=4.0, max_iterations=10, splice_threshold=45, path_precision=3 ) # Read the SVG app.logger.debug(f"Reading SVG from {output_svg_path}") with open(output_svg_path, "r") as f: svg_content = f.read() # Validate SVG if not svg_content.startswith('