Code and compiled exec are hosted on GitHub: github.com/vidmo91/imgcode
gcode visualisation made with: ncviewer.com
imgcode allows to convert quite any image file to gcode.
I made simple GUI for imgcode. run it by double-clicking imgcode_gui.ede in dist folder or with command :
python .\imgcode_gui.py
It requires imgcode_cli4gui script or exec and icon.ico file to run, so download whole repo for script usage or at least dist folder for exec usage. Parameters are the same as in CLI version, they're specified below.
The CLI version of imgcode have to be executed as python script or precomipiled exec file with input parameters:
.\python.exe image_path output_file_path x_offset_mm y_offset_mm output_image_horizontal_size_mm pixel_size_mm feedrate max_laser_power number_of_colours .\python.exe lena.png test.nc 0 0 10 0.2 100 255 5 .\python.exe "C:\Documents\laser files\lena.png" "C:\laser files\out files\output_gcode.nc" 0 0 10 0.2 220 1000 5
python .\imgcode.py image_path output_file_path x_offset_mm y_offset_mm output_image_horizontal_size_mm pixel_size_mm feedrate max_laser_power number_of_colours python .\imgcode.py lena.png test.nc 0 0 10 0.2 100 255 5 python .\imgcode.py "C:\Documents\laser files\lena.png" "C:\laser files\out files\output_gcode.nc" 0 0 10 0.2 220 1000 5
Exec I made is in dist folder and is precompiled for Windows x64. I tested it on Win10 and Win7. It is much slower than python script, but it requires minimal effort .
Required input parameters:
image_path - path to image file you want to process
output_file_path - gcode file path
x_offset_mm - parameter offsetting lower left corner of image from machine's origin
y_offset_mm - same as x offset
output_image_horizontal_size_mm - horizontal size of etched image - file will be scaled to that value
pixel_size_mm - step between pixels
feedrate - speed of laser head in mm/min
max_laser_power - maximum laser power value
number_of_colours - number of colour in output picture 2 is minimum, 255 maximum.
imgcode algorithm:
read image,
convert image to grayscale,
resize image - scale is based on horizontal size and pixel size,
quantisation of color values - to the number of colors provided,
gcode generation - image size is calculated from image array size and pixel size value, laser power is taken from image pixel value.
imgcode was coded in python 3.7.2. All required python modules with version I used are listed in requirements file. I made install_requirements batch file installing all needed modules for simple Windows "installation".
Compiling to executable file can be done with pyinstaller module. First install it with command (it installs the same version I have):
pip install PyInstaller==3.4 --force-reinstall
Then compile imgcode with command (compile as one-file console application with icon.ico icon):
pyinstaller --onefile .\imgcode.py -c -i icon.ico
It should work on any PC with the same system type (Windows, Linux, etc.) and the same CPU architecture as PC it was compiled on. Before compiling again delete build folder and imgcode.spec file, otherwise it won't recompile.