You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A powerful Python tool for converting raster images (PNG, JPG, etc.) into scalable vector graphics (SVG) with optimized color simplification and transparency support.
fromcolor_image_vectorizerimportvectorize_image# Single image vectorizationresult=vectorize_image(
input_path="input.png",
output_path="output.svg",
num_colors=200,
min_contour_area=0.01
)
# Or use the class directlyfromcolor_image_vectorizerimportColorImageVectorizervectorizer=ColorImageVectorizer(
preserve_transparency=True,
use_acceleration=True# Enable Numba acceleration
)
# Process imageresults=vectorizer.process_image(
"input.png",
num_colors=8,
method='kmeans', # or 'median'
)
# Create SVGvectorizer.create_svg(
results,
"output.svg",
style='colored', # or 'outline', 'minimal', 'transparent'add_stroke=False
)
# Create previewvectorizer.create_preview(results, "preview.png")
Batch Processing
fromcolor_image_vectorizerimportbatch_vectorize# Process all images in a directoryresults=batch_vectorize(
input_dir="./images",
output_dir="./vectors",
num_colors=8,
style='colored',
preserve_transparency=True
)
Detailed Documentation
Class: ColorImageVectorizer
Main class for vectorizing color images with acceleration support.
image_path (str/Path): Path to input image or numpy array. Supports PNG, JPG, BMP, TIFF, WebP.
num_colors (int): Target number of colors for simplification.
method (str): Color simplification method:
'kmeans': K-means clustering (more accurate, slower)
'median': Median cut quantization (faster, good for images with clear color separation)
# Process with transparencyresults=vectorizer.process_image(
"image_with_alpha.png",
preserve_transparency=True
)
# SVG will maintain transparent areasvectorizer.create_svg(
results,
"output.svg",
style='transparent'# Or 'colored' with transparency
)
vectorizer=ColorImageVectorizer(
simplify_contours=True,
contour_tolerance=2.0, # Higher = more simplificationmin_contour_area=20# Ignore small details
)
About
PNG, JPG to SVG color Converter(OpenCV): Transform your PNG and JPG images into clean, scalable vector graphics with intelligent color reduction and transparency support.