A collection of Python tools designed to generate G-code for 2D plotters, writing machines, and CNC drawing robots. This repository contains two main utilities: a high-precision outline converter using Potrace and an experimental AI-powered generator.
The "Professional" tool. It uses the potrace algorithm to trace bitmap images (JPG, PNG) into high-quality vector paths (SVG) and then converts them to G-code.
- Best for: Existing images, logos, and high-contrast line art.
- Features:
- Live preview of edge detection.
- Adjustable threshold and scaling.
- Automatic G-code normalization (fits to target size).
The "Creative" tool. It can generate images from text prompts using Google's Gemini API and convert them to G-code using internal Python algorithms (Marching Squares).
- Best for: Creating new designs from scratch ("Sci-fi sheep", "Geometric flower").
- Features:
- Text-to-Image: Generates plotting-optimized line art from prompts.
- Pure Python Tracing: Does not require external tools like Potrace.
- Generates smoothness and feed rate controls.
Install the required dependencies using pip:
pip install Pillow numpy scipy requests svgpathtools shapely-
Potrace (Required only for
gcode_converter_potrace.py)- Windows: Download the binary from potrace.sourceforge.net.
- Add
potrace.exeto your system PATH, or edit the script to point to the executable location. - Linux/Mac: Install via package manager (e.g.,
sudo apt install potraceorbrew install potrace).
-
Google Gemini API Key(if uses ai mode) (Required for
ai_gcode_generator.py)- Get a free API key from Google AI Studio.
- Set the environment variable
GEMINI_API_KEYon your system.
- Run the script:
python gcode_converter_potrace.py
- Select an input image.
- Adjust the Threshold slider until the preview shows clear outlines.
- Set the Output Directory and Filename.
- Click Convert.
- Set your API Key:
- Windows (PowerShell):
$env:GEMINI_API_KEY="your_key_here" - Linux/Mac:
export GEMINI_API_KEY="your_key_here"
- Windows (PowerShell):
- Run the script:
python ai_gcode_generator.py
- Type a prompt (e.g., "Robot cat line drawing") and click Generate.
- Once generated, adjust settings and click Extract Outline to G-code.
- Add support for batch processing multiple images.
- Improve the internal "Marching Squares" algorithm in the AI tool to handle sharper corners better.
- Add a visual G-code viewer/simulator within the app.
- Create a unified GUI launcher for both tools.
- Add support for DXF export.
Open Source. Feel free to modify and distribute.