photo2cnccut

Create g-code from photos.


Keywords
cnc, gcode, g-code, image, photo, photovcarve, rastercarve
License
MIT
Install
pip install photo2cnccut==0.1.0

Documentation

photo2cnccut

picture of Mona Lisa cut on aluminum

This python script generates cnc g-code and svg files from pictures, converting grayscale pixel data to parallel lines with varying depths.

There is already a popular open source library, rastercarve, and I borrowed basic design and interfaces from it. He explains the domain well, so I recommend reading his writings.

Motivation

  • The rastercarve author seems to use his script on modern wood cutting machines, while I wanted to cut aluminum on old industrial machines. One thing I had to do, among others, was to keep g-code short as much as possible. So I wanted to omit modal codes (e.g. repetitive G0 and G1).
  • His script requires c++ g-code parser for previewing (generating svg files). Since we already have points data in Python, I wanted to generate svg files straight from them.

Installation

$ pip install photo2cnccut

This script only requires PIL or Pillow for g-code and svg. (I have lightly checked that numpy doesn't improve performance). For optional png generation, though, it invokes inkscape from shell. So you also need it then.

Usage

$ photo2cnccut aa/mona.jpg

The command requires one argument, file path to a picture. It generates g-code and svg files (aa/mona.jpg.nc and aa/mona.jpg.svg).

If there is a valid python file p2cconfig.py, in the current directory of the file path (not the shell current directory), and it has a top level variable config (python dictionary), the script reads it, and updates default configuration accordingly.

So, if you want to convert aa/mona.jpg, there should be a file aa/p2cconfig.py to change the default. It should have lines like:

config = {
    'tool_angle': 60,
}

For possible keys and values, run '-H' or '--Help', or check the code photo2cnccut.ui._CONFIG.

(For other commandline options, run '-h' or '--help', or check the code photo2cnccut.ui._build_args).

Usage2

If there is also a valid python file p2cmodule.py, in the current directory of the file path, and it has a top level variable Data (python class), the script runs with it, instead of built-in photo2cnccut.line.Data.

It should make customization a bit easier.

License

The software is licensed under The MIT License. See LICENSE.