GithubHelp home page GithubHelp logo

khlick / gcode-converter Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 413 KB

This project was created to support hobbyists and professionals in laser engraving, providing an easy way to convert common file formats to G-code.

License: MIT License

gcode-converter's Introduction

Laser Engraving G-code Generation Tools

This repository contains tools for converting SVG and PNG images to G-code for use with laser engravers. This project was created to support hobbyists and professionals in laser engraving, providing an easy way to convert common file formats to G-code.

svg_to_gcode.py

Converts SVG paths to G-code.

Usage

python svg_to_gcode.py <svg_file_path> <output_gcode_path> --power=<laser_power> --feed_rate=<engraving_speed> --longest_side=<max_length_of_cut> --center_offset=<X_offset,Y_offset>
  • <svg_file_path>: Path to the input SVG file.
  • <output_gcode_path>: Path to save the generated G-code.
  • --power: Laser power setting (default 1000).
  • --feed_rate: Feed rate (speed) for engraving (default 1000).
  • --longest_side: Optional. Length of the longest side of the engraving in millimeters.
  • --center_offset: Optional. X and Y offset in millimeters to center the cut.

image_to_gcode.py

Converts PNG images to G-code by tracing the image contours.

Usage

python image_to_gcode.py <image_path> <output_gcode_path> --power=<laser_power> --feed_rate=<engraving_speed> --longest_side=<max_length_of_cut> --center_offset=<X_offset,Y_offset> --threshold=<threshold_level>
  • <image_path>: Path to the input .png image file.
  • <output_gcode_path>: Path to save the generated G-code.
  • --power: Laser power setting (default 1000).
  • --feed_rate: Feed rate (speed) for engraving (default 1000).
  • --longest_side: Optional. Length of the longest side of the engraving in millimeters.
  • --center_offset: Optional. Center offset (X, Y) in millimeters to align the center of the scaled cut.
  • --threshold: Optional. Thresholding level for processing the image (default uses adaptiveThresholding).

Installation and Environment Setup

Clone the repository and navigate to the repository directory:

git clone https://github.com/Khlick/gcode-converter.git
cd gcode-converter

To use these tools, we recommend creating a Python environment using venv or conda. Activate the environment and install the required Python packages.

Using venv

python -m venv venv
source venv/bin/activate  # On Windows use `venv\Scripts\activate`
pip install -r requirements.txt

Using conda

conda create --name myenv python=3.8
conda activate myenv
conda install --file requirements.txt

Examples

Converting an SVG to G-code

Produce a cut of the following svg: example1

python svg_to_gcode.py img/example.svg gcode/example1.gcode --power 1000 --feed_rate 600 --longest_side 45 --center_offset (40,40)

Produces the following gcode (read into LaserGRBL v5.7.0): example1output

Converting a PNG image to G-code

Produce a cut of the following svg: example1

python image_to_gcode.py img/example2.png gcode/example2.gcode --power 1000 --feed_rate 600 --longest_side 50 --center_offset(20,20)

Produces the following gcode (read into LaserGRBL v5.7.0): example1output


Dependencies

  • Python (3.12.0): A high-level, interpreted programming language known for its ease of use.

Installed Packages

  • OpenCV-Python: A library of Python bindings designed to solve computer vision problems.
  • Matplotlib: A comprehensive library for creating static, animated, and interactive visualizations in Python.
  • Numpy: A fundamental package for scientific computing with Python.
  • svgpathtools: A collection of tools for manipulating and analyzing SVG Path objects and Bezier curves.

To install these dependencies, run the following command:

pip install opencv-python matplotlib numpy svgpathtools

Alternatively, you can use the provided requirements.txt file with the following command:

pip install -r requirements.txt

References

For more information on the usage and capabilities of the tools used, please refer to the official documentation:

Please ensure you have the correct version of Python installed and the above packages updated to their latest versions to avoid compatibility issues.

License

This project is open-sourced under the MIT License (see LICENSE for details).

gcode-converter's People

Contributors

khlick avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.