https://github.com/mtgrosser/dmtx
Pure Ruby Datamatrix generator
https://github.com/mtgrosser/dmtx
data-matrix datamatrix datamatrix-generator png ruby svg
Last synced: 11 days ago
JSON representation
Pure Ruby Datamatrix generator
- Host: GitHub
- URL: https://github.com/mtgrosser/dmtx
- Owner: mtgrosser
- License: mit
- Created: 2021-08-31T10:54:35.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-03-27T23:01:03.000Z (about 1 year ago)
- Last Synced: 2025-12-13T08:14:42.453Z (5 months ago)
- Topics: data-matrix, datamatrix, datamatrix-generator, png, ruby, svg
- Language: Ruby
- Homepage:
- Size: 31.3 KB
- Stars: 7
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://badge.fury.io/rb/dmtx)
[](https://github.com/mtgrosser/dmtx/actions/workflows/build.yml)
# dmtx
Pure Ruby Data Matrix generator
## Installation
In your Gemfile:
```ruby
gem 'dmtx'
```
## Usage
```ruby
dmtx = Dmtx::DataMatrix.new('Chunky Bacon')
puts dmtx.to_s
██ ██ ██ ██ ██ ██ ██ ██
██ ██████ ██ ██ ████
████ ██ ██████████████ ████
██ ████ ██ ██████ ██ ██
██ ████ ██ ██ ██████
██ ██████ ████████████ ████
██ ██ ████ ██ ██
██ ██ ██████ ██ ██
██ ████ ████ ████████
██ ████ ██ ████ ██ ████
████ ██████████████
██ ██ ████ ████ ██ ██ ████
██ ████ ██ ██
████████ ██ ██ ████ ██
██ ██ ██████ ██████ ██
████████████████████████████████
dmtx.width
=> 16
dmtx.height
=> 16
dmtx.encoding
=> :ascii
dmtx.encoded_message
=> [68, 105, 118, 111, 108, 122, 33, 67, 98, 100, 112, 111,
62, 103, 49, 93, 99, 53, 117, 202, 250, 186, 232, 14]
# Generate SVG
dmtx.to_svg
=> "
# raw PNG data
dmtx.to_png.to_s
=> "\x89PNG..."
# PNG default options
dmtx.to_png(mod: 8, pad: 2, bgcolor: nil, color: '#000')
# Integer representation
dmtx.to_i
=> 77194835539484717974890203635482091341863808501307723137647139603919014133759
# Binary representation
dmtx.to_i.to_s(2)
=> "1010101010101010
1011101010000011
1101011111110110
1001101011101001
1001100101001110
1011101111110011
1001011001001000
1000100001110101
1011000110111100
1011001001101011
1100000111111100
1010110110101011
1001101001000000
1111001010001101
1010111001110010
1111111111111111"
# Choose encoding
Dmtx::DataMatrix.new('Chunky Bacon', encoding: :txt)
# GS1 DataMatrix
Dmtx::DataMatrix.new("\x1d01095011010209171719050810ABCD1234\x1d2110", encoding: :gs1)