Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spider-gazelle/qr-code
a QR Code implementation written in crystal lang
https://github.com/spider-gazelle/qr-code
Last synced: 3 months ago
JSON representation
a QR Code implementation written in crystal lang
- Host: GitHub
- URL: https://github.com/spider-gazelle/qr-code
- Owner: spider-gazelle
- License: mit
- Created: 2020-11-02T22:00:52.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-01-04T12:42:30.000Z (10 months ago)
- Last Synced: 2024-06-21T18:09:40.741Z (5 months ago)
- Language: Crystal
- Size: 26.4 KB
- Stars: 17
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - qr-code - QR Code generator (Algorithms and Data structures)
README
# Crystal Lang QR Code
[![CI](https://github.com/spider-gazelle/qr-code/actions/workflows/ci.yml/badge.svg)](https://github.com/spider-gazelle/qr-code/actions/workflows/ci.yml)
Native crystal lang QR code, no external dependencies
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
qr-code:
github: spider-gazelle/qr-code
```2. Run `shards install`
## Usage
```crystal
require "qr-code"qr = QRCode.new("my string to generate", size: 4, level: :h)
puts qr.to_s```
output
```
xxxxxxx x x x x x xx xxxxxxx
x x xxx xxxxxx xxx x x
x xxx x xxxxx x xx x xxx x
... etc
```### Doing your own rendering
```crystal
require "qr-code"qr = QRCode.new("my string to generate", size: 4, level: :h)
qr.modules.each do |row|
row.each do |col|
print col ? '#' : ' '
endprint "\n"
end
```### Rendering a SVG
```crystal
require "qr-code"svg_string = QRCode.new("my string to generate").as_svg
```### Rendering a PNG
you'll need to add [stumpy_png](https://github.com/stumpycr/stumpy_png) to your `shard.yml` dependencies
```crystal
require "qr-code"
require "qr-code/export/png"# size == width, and QR codes are square
png_bytes = QRCode.new("my string to generate").as_png(size: 256)
```## Credits
Based off the ruby gem: https://github.com/whomwah/rqrcode_core
Which was adapted from the javascript library: https://github.com/kazuhikoarase/qrcode-generator