Skip to main content

gcode2image

Commanline tool to convert gcode to pixel exact image files.

This 2D viewer - images are 2D (no Z coordinates) - has as strong points that it shows gray levels and thus is able to show a realistic representation of laser engravings. Images can be viewed while converting gcode and the exact placing and size of the gcode can be shown. Since version 2.4.0 repeated writes to the same pixel locations can be shown (option --incremental). This means that the simulated engraving is pretty close to actual laser engraving. It is also possible to show speed movement G0 code.

A typical command: gcode2image --showimage --flip test.gc test.png

This converts gcode file test.gc to image file test.png. (You can change the image file extension to .jpg or other, to get another image file format.) It shows the result image in an external viewer (platform dependent) and flips the image upside down because the gcode coordinate system and image coordinate system differ.

To get a precise idea of the location and orientation of the gcode, the following options can be used:

gcode2image --showimage --flip --showorigin --grid test.gc test.png

This generates a 1 cm (per axis) grid and shows the origin X0Y0.

gcode2image can be used alongside grblhud, image2gcode and svg2gcode for a commandline driven workflow. (https://github.com/johannesnoordanus/.)

Please consider supporting me, so I can make this application better and add new functionality to it: http://paypal.me/johannesnoordanus/5,00

Install:

Depends on python libraries numpy and PIL. pip install takes care of that.

> pip install gcode2image

Note that some managed linux distributions do not allow system wide installs using pip, in that case use pipx:

> pipx install gcode2image

Usage:

$ gcode2image --help
usage: gcode2image [-h] [--resolution <default: 0.1>] [--maxintensity <default: 255>] [--showimage] [--showG0] [--showorigin] [--flip] [--grid] [--incremental] [-V]
                   gcode image

Convert a gcode file to image.

positional arguments:
  gcode                 name of gcode file to convert
  image                 image out

options:
  -h, --help            show this help message and exit
  --resolution <default: 0.1>
                        define image resolution by pixel size (mm^2)
  --maxintensity <default: 255>
                        set maximum intensity for this image, typically 'max laser power' of the source gcode file
  --showimage           show b&w converted image
  --showG0              show G0 moves
  --showorigin          show image origin (0,0)
  --flip                flip image updown
  --grid                show a grid 10mm wide
  --incremental         show incremental burns
  -V, --version         show version number and exit

Example:

A rectangle in gcode:

M4 S300         ; set write mode (constant burn) and intensity
G0 X0Y0         ; move head to X0 Z0
G1 X25          ; move head to X25 and burn with intensity 300 (moves head on the X-axis)
G1 Y25          ; move head to Y25 and burn with intensity 300  (moves head on the Y-axis)
G1 X0           ; move head to X0 and burn with intensity 300  (moves head back on X-axis)
G1 Y0           ; moves head to Y0 and burn with intensity 300 (moves head beck on the Y-axis)

Make a file 'testje.gc' (for example) and add the above lines. Run it: gcode2image --showimage --flip testje.gc testje.png

This results in image file testje.png that has the square at the borders (note that gcode2image outputs the minimum number of pixels in X and Y)

If you add the below line at the end of the gcode file, an extra line from (0,0) to the centre of the image will show up. This will make it easier to see the result.

G1 X12.5Y12.5 ; move head to centre and burn with intensity

gcode2image --showimage --flip --showorigin --grid --showG0 testje.gc testje.png

This will show the origin (X0Y0), a grid and the gcode image containing a line from the origin to the centre of the screen.

Metadata

Release files for gcode2image 2.4.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gcode2image 2.4.5
File Size Uploaded
gcode2image-2.4.5.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gcode2image 2.4.5
File Interpreter ABI Platform
gcode2image-2.4.5-py3-none-any.whl Python 3 none any Details

Total release size: 15.7 kB

Release files / gcode2image-2.4.5.tar.gz

Download URL gcode2image-2.4.5.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
80bc69fa858a7aaebb8442c7368307fb5d596da24e947791080a31688beaa1c6
BLAKE2b-256 checksum
How to use checksums
185f5d320205b37927ac573dc13195765b4dd3e3dadfe66792a799c14d3a4087
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.34.2

Release files / gcode2image-2.4.5-py3-none-any.whl

Download URL gcode2image-2.4.5-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0291d8ba5dcb0fbe7f3380e542719e5c52741e9dcd5d53cb4ff7251a91447bd
BLAKE2b-256 checksum
How to use checksums
c1c709592d35ed6056417dcc7a6f8fc748b15d6a1137420da927aae1499633c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.34.2

Release history Release notifications | RSS feed

2.4.6

2 release files

This release

2.4.5 This release

2 release files

2.4.4

2 release files

2.4.3

2 release files

2.4.2

2 release files

2.4.1

2 release files

2.4.0

2 release files

2.3.2

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page