AkashKumarave commited on
Commit
e545804
·
verified ·
1 Parent(s): 4878619

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -14
app.py CHANGED
@@ -8,28 +8,41 @@ import os
8
  app = Flask(__name__)
9
  CORS(app, resources={r"/vectorize": {"origins": "*"}})
10
 
11
- def convert_to_vector(image):
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  input_path = "temp_input.jpg"
13
  output_path = "temp_output.svg"
14
 
15
  # Save the input image to a temporary file
16
  image.save(input_path)
17
 
18
- # Convert the image to SVG using vtracer with default settings
19
  vtracer.convert_image_to_svg_py(
20
  input_path,
21
  output_path,
22
- colormode="color",
23
- hierarchical="stacked",
24
- mode="spline",
25
- filter_speckle=4,
26
- color_precision=6,
27
- layer_difference=16,
28
- corner_threshold=60,
29
- length_threshold=4.0,
30
- max_iterations=10,
31
- splice_threshold=45,
32
- path_precision=3
33
  )
34
 
35
  # Read the SVG content
@@ -55,7 +68,7 @@ def vectorize_endpoint():
55
  else:
56
  return jsonify({'error': 'No image data provided'}), 400
57
 
58
- # Process the image to SVG
59
  svg_content = convert_to_vector(image)
60
 
61
  # Return the SVG as a response
 
8
  app = Flask(__name__)
9
  CORS(app, resources={r"/vectorize": {"origins": "*"}})
10
 
11
+ def convert_to_vector(
12
+ image,
13
+ colormode="color",
14
+ hierarchical="stacked",
15
+ mode="spline",
16
+ filter_speckle=4,
17
+ color_precision=6,
18
+ layer_difference=16,
19
+ corner_threshold=60,
20
+ length_threshold=4.0,
21
+ max_iterations=10,
22
+ splice_threshold=45,
23
+ path_precision=3
24
+ ):
25
  input_path = "temp_input.jpg"
26
  output_path = "temp_output.svg"
27
 
28
  # Save the input image to a temporary file
29
  image.save(input_path)
30
 
31
+ # Convert the image to SVG using vtracer
32
  vtracer.convert_image_to_svg_py(
33
  input_path,
34
  output_path,
35
+ colormode=colormode,
36
+ hierarchical=hierarchical,
37
+ mode=mode,
38
+ filter_speckle=int(filter_speckle),
39
+ color_precision=int(color_precision),
40
+ layer_difference=int(layer_difference),
41
+ corner_threshold=int(corner_threshold),
42
+ length_threshold=float(length_threshold),
43
+ max_iterations=int(max_iterations),
44
+ splice_threshold=int(splice_threshold),
45
+ path_precision=int(path_precision)
46
  )
47
 
48
  # Read the SVG content
 
68
  else:
69
  return jsonify({'error': 'No image data provided'}), 400
70
 
71
+ # Process the image to SVG with default settings
72
  svg_content = convert_to_vector(image)
73
 
74
  # Return the SVG as a response