barcode-generator
Scannednpx machina-cli add skill dkyazzentwatwa/chatgpt-skills/barcode-generator --openclawBarcode Generator
Generate barcodes in various formats for retail, inventory, and identification. Supports 1D barcodes (Code128, EAN, UPC) and batch generation from CSV.
Quick Start
from scripts.barcode_gen import BarcodeGenerator
# Generate barcode
gen = BarcodeGenerator()
gen.generate("123456789012", format="ean13", output="barcode.png")
# Code128 (variable length)
gen.generate("ABC-12345", format="code128", output="product.png")
# Batch from CSV
gen.batch_generate("products.csv", code_column="sku", output_dir="./barcodes")
Features
- Multiple Formats: Code128, EAN13, EAN8, UPC-A, Code39, ITF, ISBN
- Output Formats: PNG, SVG, PDF
- Customization: Size, colors, text display
- Batch Generation: From CSV files
- Validation: Check digit calculation and verification
API Reference
Basic Generation
gen = BarcodeGenerator()
# Generate with auto-format detection
gen.generate("123456789012", output="barcode.png")
# Specific format
gen.generate("12345678", format="ean8", output="barcode.png")
Customization
gen.generate(
"ABC123",
format="code128",
output="barcode.png",
width=300, # Image width
height=150, # Image height
show_text=True, # Show code below barcode
font_size=12, # Text size
foreground="black", # Bar color
background="white" # Background color
)
Batch Generation
# From CSV
gen.batch_generate(
"products.csv",
code_column="sku",
format="code128",
output_dir="./barcodes",
filename_column="product_name" # Use product name as filename
)
# From list
codes = ["ABC001", "ABC002", "ABC003"]
gen.batch_generate_list(codes, format="code128", output_dir="./barcodes")
Validation
# Validate barcode format
is_valid = gen.validate("5901234123457", format="ean13")
# Calculate check digit
check = gen.calculate_check_digit("590123412345", format="ean13")
# Returns: 7
# Generate with auto check digit
gen.generate("590123412345", format="ean13", auto_check_digit=True)
Output Formats
# PNG (default)
gen.generate("123", format="code128", output="barcode.png")
# SVG (vector)
gen.generate("123", format="code128", output="barcode.svg")
# PDF
gen.generate("123", format="code128", output="barcode.pdf")
CLI Usage
# Generate single barcode
python barcode_gen.py --code "123456789012" --format ean13 --output barcode.png
# Code128
python barcode_gen.py --code "ABC-12345" --format code128 --output product.png
# Custom size
python barcode_gen.py --code "12345" --format code39 --width 400 --height 200
# Batch from CSV
python barcode_gen.py --batch products.csv --column sku --format code128 --output-dir ./barcodes
# Validate
python barcode_gen.py --validate "5901234123457" --format ean13
CLI Arguments
| Argument | Description | Default |
|---|---|---|
--code | Code to encode | - |
--format | Barcode format | code128 |
--output | Output file | - |
--width | Image width | 300 |
--height | Image height | 150 |
--no-text | Hide code text | False |
--batch | CSV file for batch | - |
--column | Code column in CSV | code |
--output-dir | Output directory | . |
--validate | Validate code | - |
Supported Formats
| Format | Length | Characters | Use Case |
|---|---|---|---|
code128 | Variable | ASCII | General purpose |
ean13 | 13 | Digits | Retail products |
ean8 | 8 | Digits | Small products |
upca | 12 | Digits | US retail |
code39 | Variable | A-Z, 0-9, symbols | Industrial |
itf | Even | Digits | Shipping |
isbn13 | 13 | Digits | Books |
isbn10 | 10 | Digits + X | Books (legacy) |
Examples
Product Label
gen = BarcodeGenerator()
gen.generate(
"5901234123457",
format="ean13",
output="product_barcode.png",
width=250,
height=100,
show_text=True
)
Inventory Tags
gen = BarcodeGenerator()
inventory = [
{"sku": "INV-001", "name": "Widget A"},
{"sku": "INV-002", "name": "Widget B"},
{"sku": "INV-003", "name": "Widget C"}
]
for item in inventory:
gen.generate(
item["sku"],
format="code128",
output=f"./tags/{item['name']}.png"
)
Book ISBN
gen = BarcodeGenerator()
# ISBN-13 barcode
gen.generate(
"9780134685991",
format="isbn13",
output="book_barcode.png"
)
Batch Product Labels
gen = BarcodeGenerator()
# products.csv:
# sku,product_name,price
# 123456789012,Widget A,9.99
# 234567890123,Widget B,14.99
gen.batch_generate(
"products.csv",
code_column="sku",
format="ean13",
output_dir="./product_labels",
filename_column="product_name"
)
Check Digit Calculation
The generator can automatically calculate and append check digits:
gen = BarcodeGenerator()
# EAN-13: 12 digits + 1 check digit
gen.generate("590123412345", format="ean13", auto_check_digit=True)
# Generates barcode for "5901234123457"
# Manually calculate
check = gen.calculate_check_digit("590123412345", format="ean13")
print(f"Check digit: {check}") # 7
Dependencies
python-barcode>=0.15.0
Pillow>=10.0.0
Limitations
- Some formats have strict length requirements
- Characters must match format specifications
- PDF output may require additional fonts
- Very long codes may not scan well at small sizes
Source
git clone https://github.com/dkyazzentwatwa/chatgpt-skills/blob/main/barcode-generator/SKILL.mdView on GitHub Overview
Barcode Generator creates Code128, EAN13, EAN8, UPC-A, Code39, ITF, and ISBN barcodes for retail, inventory, and labeling. It supports single-barcode generation, batch creation from CSV, and multiple output formats (PNG, SVG, PDF) with customization and validation options.
How This Skill Works
Instantiate BarcodeGenerator and call generate(code, format, output) to create a barcode image. For batch work, use batch_generate or batch_generate_list with a CSV or code list, saving files to a specified directory. The tool also offers validate and calculate_check_digit, and can auto-check digits when requested.
When to Use It
- Label a single product with an EAN-13 barcode for retail shelves
- Encode alphanumeric SKUs as Code128 barcodes for inventory systems
- Batch generate barcodes from a supplier CSV (e.g., products.csv) using a code column
- Export barcodes in PNG, SVG, or PDF for labeling, packaging, or print-ready media
- Validate existing codes and compute missing check digits before printing
Quick Start
- Step 1: from scripts.barcode_gen import BarcodeGenerator; gen = BarcodeGenerator()
- Step 2: gen.generate("123456789012", format="ean13", output="barcode.png")
- Step 3: gen.batch_generate("products.csv", code_column="sku", output_dir="./barcodes")
Best Practices
- Choose the correct format for the use case (EAN/UPC for retail, Code128 for alphanumeric SKUs)
- Ensure the CSV batch has the required code_column and, if needed, a filename_column for naming outputs
- Enable check digit validation or use calculate_check_digit when generating codes
- Select output formats based on downstream needs: PNG for quick prints, SVG for scalable labels, PDF for batch printing
- Use show_text and font_size to keep codes readable on small labels
Example Use Cases
- Generate a single EAN-13 barcode for a product and save as barcode.png
- Batch generate Code128 barcodes from products.csv with SKU as the code column
- Create UPC-A barcodes for US retail items and export as barcodes.svg
- Produce Code39 barcodes with human-readable text below for inventory labels
- Validate an existing EAN-13 and compute its missing check digit