Image to DXF Converter
Operator: Abdulla Al Fahad. How tools are built and checked
A scanned sketch or a logo is a grid of grey pixels, and a laser cutter or CNC router needs lines at a known size. The step between them is tracing: deciding which pixels are ink, following their edges, and describing the result with as few points as the shape allows, so the cutter does not chase every pixel of noise.
This page traces in your browser, previews the nodes it created, sets the real size from a scan resolution or a length you know, and writes DXF R12, DXF R2000 or SVG.
Key features
- Automatic (Otsu) or manual threshold and an invert switch, with a black-and-white preview of exactly what will be traced
- Removal of specks, and of holes inside shapes, smaller than an area in pixels that you set
- Outline tracing around every dark region, or centerline tracing along each stroke after thinning
- Douglas-Peucker simplification with a tolerance in pixels, optional smoothing, and a greedy fit that turns curved runs into arcs and closed round loops into CIRCLE entities
- Real size from a scan DPI of the original, the real width or height of the whole picture, or the real width of the traced drawing, in millimetres or inches
- DXF R12 (POLYLINE) or R2000 (LWPOLYLINE with bulges) and SVG, with a node and path count shown before export
How the tracing and the DXF work
Outline tracing walks the pixel edges between ink and background, so every boundary becomes a closed loop with only its corners kept. A drawn stroke therefore becomes two loops, an outside and an inside, and a ring becomes two circles. Centerline tracing thins the ink with the Zhang-Suen algorithm, removes the staircase pixels that thinning leaves at corners, and walks the skeleton from endpoints and junctions. A stroke becomes one line, but thinning shortens every open end by about half the stroke width, and a stroke thicker than a few dozen pixels gives a poor result.
After tracing, each loop is optionally rounded by Chaikin corner cutting limited to 1.5 pixels per step, so long straight sides keep sharp corners. A greedy pass then walks the path and, from each vertex, finds the longest straight run and the longest circular arc that stay inside the tolerance, keeping the arc only when it covers clearly more of the path. The arc becomes a bulge on the polyline vertex, which is the tangent of a quarter of the arc's angle. A loop that is a single circle becomes a CIRCLE. Arcs may stray 1.5 times the tolerance because a pixel grid is noisy.
R12 stores a polyline as a POLYLINE entity followed by VERTEX entities and a SEQEND, with the bulge on each vertex. R2000 adds LWPOLYLINE, a single entity with a vertex count and optional bulges, handles on every entity and a unit code in the header. The R2000 file written here has only HEADER, TABLES and ENTITIES sections. It was checked by re-reading it with a DXF parser, not by opening it in a CAD program, and AutoCAD is known to want more (blocks, objects and owner handles), so choose R12 for AutoCAD, CAM software and old controllers.
The DXF y axis points up, so the traced y is flipped and the picture's lower left corner sits at the origin. The SVG is cropped to the traced drawing, uses the same units and is flipped back so it looks like the picture.
How it works
The picture is opened at up to 2,400 px on the long side. If the original is larger, the DPI you enter refers to the original and the page converts, so the size does not depend on the working copy.
The trace runs in a worker that is cancelled and restarted whenever you change a setting, and the scale and units are applied afterwards without tracing again.
Common use cases
- A club logo scanned at 600 dpi is traced in outline mode with the tolerance at 1.5 px, and the SVG goes to a vinyl cutter at the real width of 90 mm.
- A hand-drawn floor plan on graph paper is thinned to centerlines. The tolerance of 2 px merges the wobble in each wall into a straight segment, and Cut spurs removes the short stubs where lines cross.
- A photographed gasket outline with a known width of 120 mm is scaled with Real width of the traced drawing, which ignores the margin of the photo.
How to use this tool
- Open the picture and watch the Black and white preview while you adjust the threshold or leave Otsu on.
- Choose Outline for filled shapes such as a logo, or Centerline for line art that should be single lines.
- Raise Remove specks until dust is gone, and set the tolerance until the node count is reasonable.
- Set the size by DPI or by a length you know, and pick millimetres or inches and the DXF version.
- Download the DXF, and the SVG if you also want the lines for a design tool.
Example
A 300 × 200 px sketch scanned at 254 dpi (0.1 mm per pixel): a ring of 50 px radius, a rectangular frame and a 120-degree arc stroke
Centerline method, automatic threshold, tolerance 1 px, arcs on, DXF R12 then R2000Trace summary, then the exported DXF read back
3 paths, one of them a circle, 6 nodes and 1 arc; the ring becomes a CIRCLE of radius 5.00 mm
Extents 21.9 × 12.5 mm
Read back with a DXF parser: 2 polylines and 1 circle on layers 0 and TRACE with the same extents, in both R12 and R2000Edge cases to watch
A photograph is not a drawing. Soft shadows and gradients become ragged outlines whichever threshold you pick, so flatten the lighting first.
Tracing finds edges, not intent: two overlapping shapes become one outline, and a dashed line becomes many short paths.
The DXF holds geometry only. There is no text, no hatching and no layers beyond the one you name.
- When two lines in the photo touch, the threshold is usually too high; lower it until the gap opens before you raise the speck size.
- If the drawing opens 25.4 times too large or too small, the unit is the cause: R12 has no unit setting and simply holds the numbers in the unit chosen here, while R2000 also writes a unit code. Pick millimetres or inches to match what the CAD program assumes.
Common errors and how to fix them
- "The picture has more than 200,000 outlines or 3,000,000 corner points"
- Raise the speck size, or pick a threshold with more contrast. A noisy photo produces a loop for every grain.
- "Nothing is darker than the threshold, so there is nothing to trace"
- Raise the threshold, or turn on Invert if the drawing is light on a dark background.
- "No paths were left after clean-up"
- The speck size or minimum path length removed everything. Lower them.
Best practices
- Scan line art at 300 dpi or more in black and white or grey, with the paper flat, so the stroke is at least 3 pixels wide.
- Measure one known length on the paper and use Real width of the traced drawing rather than trusting a DPI that the scanner may have guessed.
Outline or centerline
Use outline when the dark areas are shapes: a logo to cut out, a gasket, a silhouette. Each shape becomes closed paths, and a hole inside it becomes a second path. Use centerline when the dark areas are strokes that stand for single lines, such as a pencil plan, a signature or an engraving path, where two parallel outline lines would double the cutting time.
Centerline on a filled blob returns the middle spine of the blob, not its outline, and a stroke more than a few dozen pixels wide thins into unstable branches. If the same picture mixes the two, trace it twice with different settings and combine the files in the CAD program.
Frequently asked questions
Which DXF version opens in AutoCAD?
Choose R12. The R2000 option writes LWPOLYLINE entities and a unit code, but only the HEADER, TABLES and ENTITIES sections, and it has been verified by re-reading it with a parser, not in AutoCAD. AutoCAD expects the additional structures of a full R2000 file, so it may refuse it, while R12 is read by AutoCAD, most CAM programs and older controllers.
Why is my centerline shorter than the stroke I drew?
Thinning removes pixels from the ends as well as the sides, so each free end loses about half the stroke width. Draw the line a little past where it must end, or trim in the CAD program.