Table of Contents
1.0 Introduction
In this ultimate guide for converting files to g-code, we will delve in-depth to the raster and vector file types that you can convert to G-code.
We will discover how CNC machinists can further expand the files suitable for cnc cutting by converting their JPG, PNG, STL, DXF, DWG files (and more) to a G-code file format, including CNC, .NC and TAP.
Those who have constant requirements to convert files to G-code may wish to make-use of a batch conversion tool, this is software which will automatically convert a large number of files in a single operation. We will discuss how this is possible with suitable CAD/CAM batch conversion software.
This article also considers the requirements of users who wish to convert their files to g-code offline, by downloading and installing Windows or macOS software to convert their files. This ultimate guide is the prime destination for all machinists wishing to convert their files, therefore, without further ado, let’s jump right in!
2.0 What is G-Code?
Mostly all products these days are manufactured using a CNC machine. CNC stands for Computer Numerical Control and is a machine that uses computer software to produce a product or object to a drawing specification. This process is commonly called Computer Aided Manufacturing (CAM).
CNC machines require inputs that the machine then translates into machining actions like drilling or cutting. The ability of a CNC system to execute these instructions is reliant on outputs from CAM software in the form of G-code.
There are multiple G-code file extensions produced by a range of different CAM software programs. However, regardless of extension, the file should contain the instructions to aid the manufacturing process.
To create G-code, CNC machinists can write the G-code program, alter existing one or generate a new program by converting CAD files to G-code.
3.0 Which file formats can be converted to G-Code?
There are many files that you can convert to G-Code from. We cover a number of them below.
3.1 How to convert STL to G-Code
STL is an acronym for STereoLithography, which is an industrial process of printing 3D models. Since STL was created in 1987, it has become the defacto format for 3D printing – something that was required due to the range of native file formats that can be created by CAD programs when 3D modelling. Most CAD packages can export to the STL format making the manufacturing or 3D printing process easier.

Dolphin triangle mesh (source)
STL is a 3D digital mesh that consists of triangles and this triangle tessellation (the interconnection of triangles) describes the surface of the model or object. The vertices in the mesh contain coordinate-based information of the model with the complexity and resolution of the model defined by the number of triangles. More triangles, more complexity.
Despite STL being a very useful and sophisticated format, it has drawbacks over G-Code, which you can read about in our guide to converting STL to G-Code. However, these drawbacks can be resolved by completing the STL to G-code conversion using a software known as a 3D slicer. Examples of common 3D slicing software include Ultimaker Cura, Simplify3D, FormWare, and ChiTuBox, just to mention a few.
As the name suggests, a 3D slicer essentially slices the 3D model into layers of a defined thickness. The software allows you to set the layer thickness as well as other settings such as the wall thickness, temperature of the extrusion, cooling, and more. The slicer then codifies the settings by creating a G-code file containing instructions that conform to your chosen settings. In that regard, you can use the G-code file generated to create a physical 3D representation of the model.
Short for the word ‘Object,’ OBJ is a file format used in 3D printing, 3D graphics design and modelling, and game development. It defines 3D geometry as well as color and texture. The color and texture properties make this format ideal for printing colored 3D objects. In this way, OBJ differs from the STL format, which does not contain color or texture information. However, OBJ is less common or universal than STL. As a result, it is supported by fewer 3D software than STL. As an ASCII-based file format, OBJ represents the 3D objects and models in a file using alphanumeric characters and special symbols. These characters and symbols form part of mathematical equations that define tessellated polygons that, combined, form the outer surface of the 3D model. The equations represent elements such as the polygons’ vertices, points, faces, curves, free-form surfaces, lines, and more. The formulae and characters define the virtual limits of a 3D model, which can be transformed into a physical 3D object through 3D printing. However, to 3D print an OBJ file, you have to undertake a few steps. Key among the steps is what is known as slicing, which simply refers to the process of converting OBJ to G-code. Completed using software known as 3D slicers, slicing entails dividing the vertical layout of a 3D model into layers of a defined thickness. The 3D printer will then print each layer individually. And it is the combination of these individually printed layers that create a physical 3D object. You can use different tools to convert OBJ to G-code in bulk, offline, and on mobile or tablet. We have discussed each of these conversion approaches below. DWG, or Drawing, is a binary vector file format that stores 3D and 2D drawing data in addition to metadata such as headers, settings, dictionaries, classes, and more. It is the default file format for AutoCAD. A proprietary format owned and maintained by the CAD behemoth Autodesk, DWG is not based on an open specification like DXF, which Autodesk also developed. Instead, its source code and definitions are closely guarded and can only be used upon purchasing a license to the RealDWG library. But software developers have made efforts to reverse engineer the source code with much success. Even so, AutoCAD displays an error message whenever it detects that a DWG file was not created using the code found in the RealDWG library. DWG is used to create and render 2D drawings and 3D models. Designers, architects, and engineers using CAD software that support DWG can also collaborate without having to convert their files to other file formats. 2D Image Printed Using a 3D Printer (source) But the utility of DWG is restricted as the file format is primarily used for design. For example, it cannot be deployed directly in CNC machining or 3D printing. CNC machines and 3D printers cannot read or interpret DWG files, but they can follow the instructions contained in G-code. This points to the need to convert DWG to G-code. And there are several ways you can complete such conversions: in bulk or offline using Scan2CAD. In fact, Scan2CAD goes a step further by enabling you to convert DWG to G-code with accurate scaling. DXF, an abbreviation for Drawing eXchange Format, is a vector file format that stores vector graphics using ASCII text or binary. (This means there are ASCII DXF files – which are more widely used – and binary DXF files.) As we have highlighted above, DXF was created by Autodesk as a way of enabling collaboration. Little wonder then that the DXF format specification and documentation have been openly published to ensure more CAD software support it. Since its creation in the early 1980s, the DXF format has primarily been used to transfer drawings and design details among designers, builders, engineers, architects, and suppliers. However, teams working in the 3D printing and CNC machining spaces cannot use it to transfer instructions for their machines or 3D printers. For the design details to be used in these scenarios, the DXF files must first be converted to G-code. You can use various approaches and tools to convert DXF to G-code. For instance, if you are working with hundreds or even thousands of files, you might consider solutions that support batch conversions. Similarly, if you do not have an internet connection, you might want to choose desktop software that can complete the conversion offline. In the below section, we detail how to convert DXF to G-code in bulk and offline software. Of the different conversion solutions in the market today, Scan2CAD stands distinct. It enables you to export DXF files as G-code. In addition, Scan2CAD includes tools that, when used, allow you to convert DXF to G-code with accurate scaling. An abbreviation for the Joint Photographic Experts Group, JPG or JPEG is a raster file format used to digitally store 2D images using the lossy compression method. As a lossy format, JPG offers a higher level of compression than PNG, a factor that comparatively reduces its quality. This image format was introduced in 1992 and has grown to be the world’s most widely used image standard. In fact, by default, your mobile phone camera saves all its images using JPG. Additionally, Common Crawl ranks JPG as the third most popular image format on the web. This popularity has been influenced by the benefits of the JPG file format. Firstly, JPG files are highly compressible, meaning they can take up less disc space. This small file size makes JPG one of the best formats for web-based images. This is because it will require additional resources that may slow down the loading speed. At the same time, JPGs support variable compression. This means you select different degrees of compression based on your needs. Thirdly, JPG images are compatible with virtually all devices and can be imported into a majority of the software. But when compared to vector file formats, JPG does not offer the same level of quality – the quality and resolution drop significantly the more you zoom into a given section. Furthermore, while a variety of devices and software, including 3D printers, support the JPG format, the format can only be used to transfer or represent an image. As such, you cannot import a JPG file directly into a 3D printer with the intention of using it directly to create a physical model. Instead, you must first convert JPG to G-code. And as with the other file formats, there are various ways to complete the conversion. PNG, or Portable Network Graphics, is a raster file format that stores lossless, portable, compressed, bit-mapped images. In this regard, the PNG specification, which defines the PNG format, supports lossless compression. Compared to JPG’s lossy compression, PNG’s lossless method reconstructs the image data without losing any information. This means PNG images are higher quality than JPG images. PNG was first introduced in 1996. Its development aimed to improve and replace the Graphics Interchange Format (GIF). Though possibly unintentional, the improvements gave rise to numerous advantages that have cemented PNG’s superiority over other raster file types, particularly the JPG and GIF. For instance, PNGs maintain better detail and color contrast than JPGs. They also boast better text readability than JPGs. PNGs also offer a wide color depth, support transparency, and are ideal for editing images. But when compared to vector image formats like SVG or CAD design formats like DXF and DWG, PNG lags a tad behind, particularly when it comes to resolution. Scaling up a PNG image distorts the quality, as it makes the image appear more pixelated. At the same time, PNG images cannot be used directly to print 3D objects or create objects using CNC machines. This is because 3D printers and CNC machines can only read and interpret G-code, which contains instructions that govern their movements. Fortunately, you can go around this problem by converting PNG to G-code. Short for Scalable Vector Graphics, SVG is a digital vector format that stores graphics and text in Extensible Markup Language (XML) files. The graphics are defined by mathematical formulas based on geometrical shapes such as lines, circles, and curves that are laid over a cartesian plane. This means the quality of the images does not change however much you resize them. As a result, SVG files are preferred by web designers and graphic designers who wish to exploit the format’s resizing capabilities. Generally, the SVG format is primarily used to display 2D illustrations, logos, charts, infographics and graphics on websites. And being XML-based, it can be created or edited using either text editors or vector graphics software. In addition, it can be rendered by software that can interpret XML files, including web browsers. But as with the other image formats, SVG cannot be directly imported into CNC machines or 3D printers with the aim of creating the objects represented therein. Therefore, it is crucial first to convert SVG to G-code.[/su_spoiler]
G-code is one of the industry-standard file formats for CNC machines. The power in the format lies in its simplicity, unlike many other formats, the code of the G-code file format can be read by the human eye. This somewhat simple format contains the instructions for CNC machines including the direction, depth and rotation of the cutting machine. There are many more such ‘codes’ within the G-code file structure which defines all aspects of a CNC machine’s cutting movement. Given the benefits of g-code files for CNC machine users, if they have a design which they wish to cut, that is not in G-code format, they can convert this file to g-code using conversion software such as Scan2CAD. To save a file as g-code you must first convert the file to confirm to the G-code file structure. Most typically, CNC machinists wish to convert raster images (such as JPG, TIFF, PNG etc.) to G-code so that they may cut the design contained in their raster image with their CNC machine. The conversion of a raster image to g-code requires a raster-to-vector conversion software, such as Scan2CAD. After the image is converted to the g-code file structure, the user may save (or export) the file to a g-code file extension, such as .nc, .cnc and .tap. G-code files are designed for CNC machines, controlling every aspect of the CNC machine’s movements. Therefore almost all CNC viewers, controllers or design software applications will support G-code files. Applications which support G-code files will most-likely have the ability to open files with the .nc, .cnc and .tap extensions. This is because the file specification for files with these extensions is identical. Some software applications which open g-code files include: The list of g-code file editors is smaller than the list of g-code file viewers. Viewing the contents of a G-code file is a much more simplistic requirement than offering the complexity of editing the contents of a G-code file, especially if the software is editing in such a way that is optimal for the CNC machine’s cutting. Many G-code editing applications will run simulations of the cutting path proposed by the design held within the g-code file. After the simulation is complete, the application may provide recommendations to optimize the design for the best and least-wasteful cut. Some software applications which open g-code files include: There are very few online websites which offer to convert raster images (such as JPG, TIFF, PNG etc.) to G-code. There are few such solutions because there are many pitfalls in attempting to convert an image to G-code online. In order to convert an image to g-code, the software must first perform an accurate raster-to-vector conversion and subsequently convert the vector paths within the vector image to cut-friendly paths written in a G-code file. This is a very complex procedure which cannot realistically be achieved with a free online converter website. Instead a user should utilize an offline software application which they will download and install on their Windows or macOS computer. This software will make-us of the power of the computer’s processing to perform complex and accurate conversions of the images to g-code. One such solution us Scan2CAD. In this ultimate guide, we have discovered how CNC machinists have almost limitless options for converting their raster and vector files to g-code. From vector file formats such as DXF and DWG to raster image file formats such as PNG and JPG, they may all be converted to G-code by utilizing suitable software. As discussed in this article, the unique capabilities of g-code files make them one of the default files types for controlling CNC machines. The vast majority of CNC controller and editing software applications support the three primary g-code file formats (i.e. .CNC, .NC and .TAP.) Given the vast advantages of converting ones’ files to G-code, it may come as no surprise that many CNC machinists have attempted to perform their conversions using free online g-code conversion websites. However, as we have discussed in this article, users have found that the online conversion solutions are not accurate and not secure. Instead users opt to download software to convert their files to G-code with a Windows or macOS computer. With the introduction of CAD/CAM conversion software, users have many new options for creating suitable ‘cut-friendly’ CNC designs.3.2 How to convert OBJ to G-Code
3.3 How to convert DWG to G-Code
3.4 How to convert DXF to G-Code
3.5 How to convert JPG to G-Code
3.6 How to convert PNG to G-Code
3.7 How to convert SVG to G-Code
4.0 FAQ
4.1 Why convert to G-Code?
4.2 How can I save a file as G-Code?
4.3 What software can be used to open G-Code files?
4.4 Why should you avoid online G-Code converters?
5.0 Conclusion