Package: grbl2image
grbl2imageGenerates animage(PNG, JPEG, etc.) from aGRBLfile (.NC, .GC, ...), in Python using pillow (python3 PIL fork). It is to be used as a reusable standalone component, initially for theparent projectGRBL WebStreamerthat is a webinterface for laser cutters running on Raspi or similar SBC.The target is to generate a simply a top view of a GRBL job for my Laser (seelimitationsbelow). As of now only a subset of the GRBL commands are recognized, and more will be added along the way when their need arise. This is not meant to be the complete solution for all GRBL files, but I'll be taking requests on GitHub so don't hesitate.What it doesGenerates image from a GRBL file for a Laser jobCalculates estimated bounds of the jobCalculates an estimated time of completion of the jobLimitationsThis is made to support alasercutter/engraver,not CNC, and this is out of scope even of the end scope of library. There are already good solutions that handle the 3D component of your CNC. This is just a top view of a GRBL file, so if it works with yours CNC good for you!Therefore GRBL codes that don't make sense for a laser will be ignored and not implemented, but if you have time fork this project!AssumptionsI took some assumptions with this code, and the more mature it will get the more flexible it will be. For now, here are a few that are enforced implicitly:You work in Metric system (like you should)Default coords are ABSOLUTEOrigin is 0,0Work area is 200mm x 200mm with a resolution of 10px/mm by default (but you can change that - see examples below)Compatibility / Tested softwareSo far the tested software and empirically perceived support:LightBurn: Very good (all the jobs I made and tried rendered just fine)Technical detailsDependenciesPillow the replacement of PIL the image library :python3 -m pip install pillowSupported GRBL codesI will add them as I need them, but here are the ones that should work as of now:G0 moveG1 burnG90 coords are ABSOLUTEG91 coords are RELATIVESample usageGenerate an image from GRBL fileimportgrbl2image.grbl2imageasG2IfromPILimportImage#Generate the PIL Image object based on sample codeimg,stats=G2I.processFile("sample.gcode/Test gcode 1.nc",color="blue")print(stats)#overlay another job in the same imageimg,stats=G2I.processFile("sample.gcode/Test gcode 2.nc",targetImage=img,color="red",yoffset=300)print(stats)#final flip because the image 0,0 is top left and for us human it's at the bottom leftimg=img.transpose(Image.FLIP_TOP_BOTTOM)#show popupimg.show()Change the target image sizeDefault is 200mm x 200mm at 10px/mm resolution, but you can change that according your laser work area. Tip : better have a bigger image and then scaling down than a small image all along.importgrbl2image.grbl2imageasG2IfromPILimportImage#suppose your laser is a 40cm x 30xm for instance you could use these settings **before** calling processFile()G2I.PIXELS_PER_MM=5G2I.AREA_W_MM=300G2I.AREA_H_MM=400#Generate the PIL Image object based on sample codeimg,_=G2I.processFile("sample.gcode/Test gcode 1.nc",color="blue")#final flip because the image 0,0 is top left and for us human it's at the bottom leftimg=img.transpose(Image.FLIP_TOP_BOTTOM)#saveimg.save("laser_job_001.png")Source codeSource is MIT licensed on GitHub :https://github.com/AlanFromJapan/grbl2imageParent projectGRBL WebStreameris also on GitHub under MIT license