What G-Code is, how machines use it, and the full production pipeline — from SVG and raster images to machine-ready files for pen plotters, laser engravers, 3D printers, and CNC mills.
G-Code (Geometric Code) is the plain-text language that drives CNC machines. Each file — typically .gcode, .nc, or .cnc — is a sequence of instructions telling the machine where to move, how fast, and when to activate its tool. Lines execute top to bottom, one at a time.
Think of your design as the blueprint and G-Code as the turn-by-turn navigation. A 3D printer cannot process a JPG. A pen plotter does not know what the letter 'A' looks like. G-Code solves this by breaking any shape into elementary moves — straight lines, arcs, and tool on/off commands — that any motion controller can execute reliably.
The standard traces back to MIT in the 1950s, formalized as RS-274 in 1963 and internationally published as ISO 6983 in 1982. Despite its age, G-Code remains the universal language of fabrication — from hobbyist desktop printers to industrial five-axis mills.


Each line (called a block) is one complete instruction. The machine remembers its state between lines — a feedrate set on line 10 stays active on line 200 unless you change it. This is called modal state.
Here is a pen plotter program that draws a 50×50mm square:
G21 ; millimeters
G90 ; absolute positioning
G0 Z5.0 ; lift pen
G0 X0 Y0 ; move to origin
M3 S1000 ; pen down
G1 X50.0 Y0 F2000
G1 X50.0 Y50.0
G1 X0 Y50.0
G1 X0 Y0
M5 ; pen up
M2 ; end
Breaking down G1 X50.0 Y25.3 F1500: G1 = draw a straight line, X50.0 Y25.3 = destination, F1500 = 1500 mm/min. Notice G1 only appears once — every following coordinate line reuses it automatically until you write G0 or another motion command. Anything after a semicolon is a comment, ignored by the machine.

These commands work across virtually all firmware — from hobbyist GRBL to industrial Fanuc.
GRBL uses seconds — G4 P1.5 pauses for 1.5 seconds. Marlin uses milliseconds — G4 P1500 is the same pause. Using the wrong unit means your machine either barely pauses or freezes for minutes. Always check your firmware docs.


Plotters only understand paths — not pixels, fills, or raw text. Use Inkscape, Illustrator, or Affinity Designer to create SVG stroke paths. Convert all text to outlines. Remove fills, bitmaps, and effects — they are silently ignored by the converter.
Merge duplicate paths (the pen would trace the same line twice), simplify dense nodes, and set document dimensions in millimeters — not pixels — to avoid DPI scaling issues later.
The converter translates each path into G1 moves and inserts M3/M5 pen-lift commands between disconnected strokes. The most important setting is path sorting — which order strokes are drawn. A poor sort sends the pen zigzagging across the page thousands of times. A nearest-neighbor sort can cut travel time by 50% or more on dense artwork.
Stream the file to GRBL firmware through Universal Gcode Sender (UGS) or bCNC. The sender delivers lines one by one; GRBL translates each into stepper motor pulses.
Vector mode traces paths at constant power — use it for cutting outlines and engraved lines. Raster mode sweeps back and forth like a printer, varying power pixel-by-pixel — use it for photos and shaded fills. A single job can use both modes on separate layers.
Tools like LightBurn or LaserGRBL output M3 S[value] to fire the laser and M5 to stop it. In raster mode the S value changes on every G1 line, reproducing grayscale gradients. GRBL must be compiled in laser mode for this — it disables speed ramping and enables instant power response.
Power and speed vary dramatically by material. Always run a small power/speed grid test on the same material before starting the real job.
Laser: wear safety glasses rated for your wavelength (CO2 = 10,600nm; diode engravers ≈ 450nm — these require different eyewear). Ensure ventilation — engraving produces toxic fumes from almost all materials. Never leave a running laser unattended. CNC: clamp the workpiece before running the spindle — an unsecured piece can be thrown at speed. Know your emergency stop before you start.
Design in Fusion 360, Blender, FreeCAD, or similar. STL is the standard exchange format; STEP carries more precise geometry for engineering parts.
A slicer (PrusaSlicer, Cura, Bambu Studio) cuts the model into 0.1–0.3mm horizontal layers and calculates toolpaths, supports, infill, and bridges. A typical move looks like G1 X42.5 Y88.3 E0.0234 F4500 — moving the head while extruding exactly 0.0234mm of filament. The slicer also inserts M109 and M190 to heat the nozzle and bed before printing starts.
Marlin, Klipper, or RepRapFirmware executes the file. Klipper offloads computation to a Raspberry Pi and supports input shaping — it measures frame resonance with an accelerometer and filters it out of motion commands, reducing ringing artifacts and enabling higher print speeds.
Use Fusion 360, SolidWorks, or FreeCAD. Machined parts require tolerances of 0.01–0.05mm, so model quality directly determines part quality.
CAM software (Fusion 360 CAM, VCarve, Mastercam) lets you specify the tool, cutting strategy (adaptive clearing, contour, pocketing), depth of cut, spindle speed, and feedrate. The goal is efficient tool engagement without breaking the bit or burning the material.
Industrial CNC machines each speak their own dialect — Fanuc, Siemens Sinumerik, Heidenhain, Haas. A post-processor inside your CAM software translates generic toolpaths into the exact syntax your machine expects. Using the wrong post-processor does not just produce bad parts — it can crash the machine into the workpiece, destroying tooling and creating a safety hazard.
SVG paths use Bézier curves, arcs, and straight lines. G1 only draws straight lines — so converters must bridge the gap two ways:
Faceting breaks curves into many tiny straight segments. Smoother curves require shorter segments, which means larger files and potential motion stuttering when the machine's command buffer can't keep up.
Arc fitting is smarter: it detects when a run of short segments collectively forms a circle and replaces the whole group with a single G2 or G3 command. A circle that takes 360 G1 lines becomes one line of G-Code. Files shrink by up to 90%, motion is perfectly smooth, and the machine holds a continuous speed through the arc. Not all GRBL builds support G2/G3 — check before enabling.

Illustrator exports at 72 DPI. Inkscape before v0.92 used 90 DPI. Modern tools use 96 DPI. If your converter assumes 96 DPI but your file came from Illustrator, every dimension is 33% too large — a 100mm shape plots at 133mm. Fix: match your converter's DPI setting to your source app, or better yet, set your SVG document dimensions in millimeters to make DPI irrelevant entirely.
Core motion commands (G0, G1, G2, G3) work everywhere. Everything else — startup sequences, tool changes, comment syntax — varies by firmware family. Running G-Code from the wrong controller on a professional CNC machine does not just produce wrong output — it can cause a rapid crash into the workpiece.
Photos contain only pixels — no path data. Before a photo can be plotted or vector-engraved, it must be converted to SVG. Common approaches:


Pixel2Lines converts your photo into a clean, machine-ready SVG in professional styles built for pen plotters and laser engravers — line drawing, hatching, stippling, and more. Output paths are structured as discrete strokes, minimizing pen lifts and travel time.
Once you have the SVG, the SVG to G-Code converter generates the final file with full control over feedrate, pen-up height, laser power, and path sort order.
This two-step pipeline — photo to SVG via Pixel2Lines, SVG to G-Code via the converter — takes you from any photograph to a machine-ready file without needing vector design skills or G-Code knowledge.

Yes — for simple shapes it is a useful exercise. For anything complex, use CAM software or a dedicated converter.
Core motion commands are universal. Startup sequences, tool changes, and extended features differ significantly. G-Code for a GRBL plotter may need substantial changes to run on a Fanuc mill — and using the wrong dialect on an industrial machine can cause a crash.
GRBL is an open-source CNC firmware that runs on Arduino-class microcontrollers. It is the standard for hobbyist pen plotters, DIY laser engravers, and small CNC routers. It implements the core RS-274 standard with an acceleration-aware motion planner and look-ahead buffering.
Ballpoint: 5000–8000 mm/min. Felt-tip or brush pen: 2000–4000 mm/min. Fountain pen or glass nib: 1500–3000 mm/min. Always test on scrap paper first.
Yes. In GRBL laser mode, S can change on every G1 line — this is how raster engraving reproduces smooth grayscale gradients in a single sweep.
HPGL (Hewlett-Packard Graphics Language) was used by HP pen plotters from the 1970s–90s. It uses two-letter commands (PU = pen up, PD = pen down, PA = plot absolute) and plotter units of 40 per millimeter instead of mm or inches. Most modern plotter tools can read both formats.
NCViewer (ncviewer.com) is the fastest option — paste your file and it renders the toolpath instantly. CAMotics simulates 3D material removal for CNC work. Universal Gcode Sender has a built-in path preview. Always follow on-screen simulation with a physical dry run at safe height.
Upload any photo to get a clean, optimized SVG from Pixel2Lines, then convert it to machine-ready G-Code in one step. Works for pen plotters, laser engravers, and CNC machines.
Convert Your Photo Now
Comments
Loading comments...