How to Convert SVG to G-code

Convert SVG to G-code

G-code is a programming language with which users control machines such as laser cutters, pen plotters, and 3D printers, just to mention a few. Thus, anyone looking to create a 2D or 3D object from a virtual design or model must first convert the file containing the model to G-code. An excellent example of this in action is the SVG to G-code conversion. SVG is a vector file format that stores 2D images. If the shapes in the image are to be engraved or curved into physical shapes using milling tools – instead of being printed on paper – the SVG file must be converted to G-code. This article discusses how you can convert SVG to G-code. Additionally, it details the various ways you can prepare an SVG file for conversion.

What is SVG File Format?

Scalable Vector Graphics, or SVG for short, is a digital vector file format developed in the 1990s. It is primarily used in websites to display 2D illustrations, charts, infographics, and graphics. Being a vector format, SVG maintains the quality and resolution of the images even after scaling them up or down. 

This capability is anchored in the fact that mathematical formulas define the vector elements that make up an SVG file. When the image is resized, several variables – or even one – within the formula change. The recalculation of the formula then results in a ‘new’ high-quality image. In this way, SVG images differ from raster image formats such as JPEG, PNG, TIFF, GIF, and BMP, which are composed of pixels.

The SVG format is also popular among web developers because it is built using the Extensible Markup Language (XML). In this regard, the files store text-based information as text as opposed to shapes. Thus, search engines can read the keywords contained in the SVG images. Additionally, SVG files take up less disc space compared to raster images. This factor appeals to web developers who utilize them because they are faster to load; therefore, they do not negatively influence webpage-wide or site-wide overall loading time.

Generally, the SVG format is used in the following instances:

  • Illustrations
  • Graphs and infographics
  • Company logos
  • Website buttons and icons

If you are looking to open an SVG file, you do not need to have sophisticated image opening or editing software. This is because you can open an SVG image using any major web browser. You can also open it using Adobe Photoshop and Illustrator, GIMP, CorelDraw, Inkscape, and more. 

What is G-code?

Computer numerical control or CNC involves the automated control of machining tools or 3D printers using a computer. And because computers rely on pre-written programs in order to execute certain tasks, the control of these CNC tools is no exception. The programs used to control the CNC machines are written using a special programming language known as G-code. This implies that G-code comprises a sequence of codes that controls CNC machines. 

Specifically, the G-code specifies how the machining tool should move within a geometric grid – hence the G in G-code. The code dictates the speed of movement, whether or not the machining tool should follow a linear motion, or whether it should take on a clockwise or anticlockwise movement. Simply put, the G-code controls the movement of milling and machining tools as well as the motors of a 3D printer along the X, Y, and Z axes. It is the combination of these movements that help create a machined or 3D-printed object.

Preparing SVG file for Conversion

Why is it necessary to prepare your SVG file for conversion?

The SVG file is ideally used to represent images in a virtual setup. But if you wish to create a tangible representation of the virtual image, you must first convert SVG to G-code. The conversion will create a G-code file that contains instructions that, when fed into a machining tool, will provide a step-by-step guide on how to create the object. 

However, before you can embark on the conversion, it is crucial to consider a few factors. Firstly, some SVG files are complex in that they may contain a myriad of colors with changing gradients or even shading. They may also contain several complicated objects. Combined, these elements may prove impossible to translate to written instructions. Secondly, some SVG files contain 2D shapes. In order to idealize them for the purpose of creating 3D objects, it is vital to insert 3D information before converting SVG to G-code.These two considerations indicate the need to prepare your SVG file for conversion.

How to prepare your SVG file for conversion?

To prepare your SVG file for conversion, you must first import it into an editing software such as Adobe Illustrator or Inkscape. This is because you have to modify certain elements of the image. Then, and depending on the nature of the SVG image, do the following:

  1. Delete unnecessary elements
    You can start by deleting certain unnecessary elements, such as colors and shadings. 
  2. Look at the line colors
    Depending on the purpose for which you want to use the G-code file, it is equally important to look at whether your SVG file contains different line colors. (When it comes to laser cutting, for instance, a red-colored line indicates that the cutting tool should only etch a mark along the line. On the other hand, a blue or black line indicates that the laser should cut through the material.)
  3. Synchronize the dimensions
    You should also store the SVG image in the dimension you eventually wish to use once you embark on cutting it. 
  4. Utilize the Objects-to-path tool
    You should ensure that the shapes and text within the file show up when you convert them. You can achieve this simply using the object-to-path tool on your editing software, which commits the selected shapes and text to a path of your choice. This ensures all the shapes and text-based objects are recognized and will therefore be converted. 
  5. Optimize the SVG file
    This step is reserved as a last resort. If all the other interventions do not work, the problem could be the incompatibility of the SVG file, which affects how the file is interpreted. This can be fixed using an optimization tool. You can use several web apps, desktop software, and command-line tools to optimize your SVG files.

It is worth pointing out that some SVG files do not require much modification. This underscores the fact that you do not have to execute each of the five preparation procedures for every SVG file that you want to convert to G-code. A clean, black and white, and scaled SVG image, for instance, may only require you to complete procedures 4 and 5, or none at all. 

How to convert SVG to G-code for 2D machines?

As stated, SVG mainly comprises 2D elements. This makes converting SVG files to G-code for 2D machines relatively straightforward – you do not need to include additional 3D elements. Nonetheless, it is important to consider the purpose for which you will use the G-code file. Is it for simple CNC routing, laser cutting, or pen plotting? Answering this question will enable you to select the right software to convert SVG to G-code. These programs are specifically designed to work with a particular family of CNC machines. In that regard, they will produce G-code instructions tailored to these machines. 

SVG to G-code conversion software for 2D machines

These programs can be categorized into:

  1. SVG editor plugins and extensions
    Examples include Inkscape’s built-in extension known as Gcodetools for CNC routers and mills, as well as plotters and third-party Inkscape plugins such as GcodePlot for pen plotters
  2. Online tools such as Jscut and CAD2CNC
  3. Offline desktop software
    For laser cutting, you can utilize tools such as LaserWeb, LaserGRBL, and LightBurn, while for CNC cutting and engraving, you can use Carbide Create. Some manufacturers also create dedicated conversion software that enables you to convert SVG to G-code.

Step-by-step guide

To convert SVG to G-code using the tools listed above, follow the procedure below:

  1. Launch the software and select the machine you want to use from the list contained in the program
  2. Import your SVG file and, using the scale, check whether the size of the image falls within the dimensions of the machine’s workspace
  3. Run a simulation. This step is optional as it depends on whether your software supports the simulation. It is, however, beneficial as it lets you check whether the tool cuts or shapes conform to what you want before you can cast the instructions in stone.
  4. Export the SVG image as a G-code file

Here, you can take either of two approaches, the first of which entails saving the SVG file as a G-code. Alternatively, you can send the converted file directly to the machine without having to save the file. 

How to convert SVG to G-code for 3D machines

Converting SVG to G-code for 3D machines is a two-part process. The first part involves converting SVG to the STL format. Then you have to convert STL to G-code.

Converting SVG to STL

The first step in a two-part process, converting SVG to STL introduces 3D elements to a 2D image. This step involves raising the 2D shape such that it acquires a new dimension – a height. This process can be regarded as an extrusion. This extrusion can take many forms because the conversion from 2D to 3D does not only have to be along the Z-axis (height). The 2D shape can be extruded at an angle or varying heights. Simply put, the shape can also be extruded in different directions.

To convert SVG to STL, you can use dedicated online conversion tools such as SVG2STL and AnyConv. However, although AnyConv can convert even the most complex SVG images to G-code, it has a downside: it does not let you extrude the 2D image to create a 3D model. Similarly, while SVG2STL supports extrusion, it does not let you modify the extruded shape nor decide the plane along which the 2D shape should be extruded. These downsides indicate that online conversion tools are limited in what they can achieve.

Nonetheless, to use SVG2STL, simply follow this procedure:

  1.     Open the website
  2.     Upload the SVG file
  3.     Specify the length of the extrusion (in mm from 1 to 300)
  4.     Click Convert: the online tool shows a 3D representation of the 2D image.
  5.     Click Download the converted file.

Alternatively, you can use free online 3D modeling solutions like Autodesk TinkerCAD. And if you have access to paid CAD and CAM software, you may already know that you can use desktop software such as Autodesk Fusion360. These tools provide additional capabilities as they help you change the height of the extrusion at different sections by simply drugging the ‘handle’ up or down. You can also add or modify the extruded shape. 

Converting STL to G-code

As we previously discussed in our article on how to convert STL to G-code, you only need a program known as a 3D slicer. This software divides the 3D model into layers of a given height – you get to choose the actual length of the layers in the program’s settings. It is worth pointing out that the thinner the layers, the better the quality. The 3D slicer also allows you to play with other settings, including the wall thickness, infill pattern and density, print time and speed, support structure, temperature and cooling, just to mention a few. 

To convert an STL file to G-code, follow this procedure:

  1.     Upload the STL file into the slicer software
  2.     Tweak the settings according to your preferences
  3.     Click ‘slice’ to create a layered version of the 3D model
  4.     Save the sliced 3D model as a G-code file that you can then import into a 3D printer or CNC machine


There are two approaches you can employ whenever you want to convert SVG to G-code. The first involves creating instructions for 2D machines. This approach involves converting the SVG files directly to G-code. On the other hand, if you want to convert SVG to G-code for 2D machines, you must first convert SVG to STL and subsequently convert STL to G-code. Before embarking on the conversion, however, it is vital to use an SVG editor to modify the SVG file. The modification eliminates some aspects within the file that may complicate the conversion.


scan2cad advert for free trial