--- title: PNG JPG to SVG emoji: ✒️ colorFrom: gray colorTo: indigo sdk: gradio sdk_version: 6.5.1 app_file: app.py pinned: false license: mit suggested_hardware: cpu-basic short_description: Vectorize bitmaps into clean SVG paths --- # PNG / JPG to SVG Turns raster images into scalable SVG paths, tuned for clean line work on AI-generated drawings, logos and sketches. CPU only — no GPU needed. > Set `sdk_version` above to the value Hugging Face put in the README it > generated when you created the Space. ## Setup 1. New Space → SDK **Gradio** → hardware **CPU basic** (ZeroGPU will refuse to start, since this app has no `@spaces.GPU` function). 2. Upload `app.py`, `requirements.txt` and `README.md` to the repository root. 3. Wait for the build. First run takes 2–3 minutes. Locally: ```bash pip install -r requirements.txt python app.py ``` ## Pipeline | Stage | What happens | |---|---| | Prepare | Composite alpha onto white, fix EXIF rotation, optional 2–4× upscale | | Isolate | Autocontrast, median smoothing, threshold (Otsu, global or adaptive) | | Centerline | Zhang-Suen skeletonization, then dilation to one constant stroke width | | Trace | VTracer emits Bézier splines or polygons | | Clean up | Strip white background fills, recolor lines, set `viewBox` to source size | ## Controls that actually matter - **Upscale before tracing** — the single biggest lever for smooth curves. Start at 2×, go to 3× for small sources. - **Uniform stroke width** — pulls each line onto its centerline and redraws it at constant weight. Fixes the ragged edges typical of generated images and cuts file size by roughly half. - **Filter small specks** — removes JPEG compression artifacts. Set to 8–12 for JPG sources. - **Corner threshold** — high for soft organic lines, low for technical drawings with crisp corners. - **Adaptive threshold** — for photos of paper sketches with uneven lighting. ## Limits Photographs with gradients produce many paths and large files in color mode — lower the color depth and raise speck filtering. Fine halftone dots and screen patterns don't translate into meaningful lines. Images larger than 2600 px on the long edge are downscaled before tracing so the Space doesn't time out.