PyDataMatrix is a Python library designed to generate and decode Data Matrix barcodes. A Data Matrix barcode is a two-dimensional code composed of black and white "cells" arranged in either a square or rectangular pattern, also known as a matrix. This project aims to facilitate the use and integration of Data Matrix barcodes in various applications, providing essential functions to create and extract information from these codes.
- Generate Data Matrix barcodes from given data.
- Decode Data Matrix barcodes to retrieve stored data.
- Supports encoding data in multiple modes, including C40, Text, S01, and S02.
- Handles different character sets for flexibility in data encoding.
- Provides visualization and saving of the generated Data Matrix barcode as an image.
- Python 3.x
- PIL (Python Imaging Library) or its fork Pillow for image handling
-
Clone the repository:
git clone https://github.com/Yuriy/pydatamatrix.git cd pydatamatrix
-
Install the required dependencies: It's recommended to use a virtual environment to avoid conflicts with other Python packages.
python3 -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate` pip install pillow
-
Verify the installation: You can verify if everything is set up correctly by running:
python datamatrix.py
Here's a simple example demonstrating the generation and decoding of a Data Matrix barcode using PyDataMatrix:
import datamatrix
data = "Hello, PyDataMatrix!"
matrix = datamatrix.generate(data)
matrix.save("output.png") # Save the generated barcode as an image
import datamatrix
matrix_image = "input.png" # Path to the image of the Data Matrix barcode
data = datamatrix.decode(matrix_image)
print(f"Decoded data: {data}")
The core functionality of PyDataMatrix is provided in the datamatrix.py
file. Here is a brief overview of its contents:
- Imports: Essential libraries for mathematical operations and image handling.
- Constants: C40, Text, and other character sets used in encoding.
- Functions:
- generate(data): Generates a Data Matrix barcode from the provided data.
- decode(image_path): Decodes a Data Matrix barcode from an image file to retrieve the stored data.
We welcome contributions from the community. Here's how you can contribute:
- Fork the repository on GitHub.
- Clone your fork locally:
git clone https://github.com/YOUR-GITHUB-USERNAME/pydatamatrix.git
- Create a new branch for your feature or bugfix:
git checkout -b feature-or-bugfix-name
- Make your changes and commit them:
git commit -am "Description of changes"
- Push your changes to your fork:
git push origin feature-or-bugfix-name
- Create a pull request on the original repository.
Please ensure your code follows the project's coding guidelines and includes appropriate tests.
This project is licensed under the MIT License. See the LICENSE file for more details.