-
-
Save greenbigfrog/a642719523f451f021f20bdb3ebac3ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: qr-api | |
version: 0.1.0 | |
authors: | |
- Jonathan B. <greenbigfrog@gmail.com> | |
targets: | |
qr-api: | |
main: src/qr-api.cr | |
crystal: 0.27.0 | |
license: MIT | |
dependencies: | |
stumpy_png: | |
github: stumpycr/stumpy_png | |
qrencode: | |
github: woodruffw/qrencode.cr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "qrencode" | |
require "stumpy_png" | |
include StumpyPNG | |
qr = QRencode::QRcode.new("this is my input string") | |
size = 300 | |
dead_percentage = 23 | |
dead = (dead_percentage / 100.to_f * size).to_i | |
scale = (size - dead) / qr.width | |
qr_size = qr.width * scale + dead | |
if qr_size < size | |
dead = size - qr_size + dead | |
qr_size = qr.width * scale + dead | |
end | |
puts "Size: #{size} Scale: #{scale} Final width: #{qr_size}" | |
canvas = Canvas.new(qr_size, qr_size) do |x, y| | |
x = (x - dead / 2) / scale | |
y = (y - dead / 2) / scale | |
if 0 <= x < qr.width && 0 <= y < qr.width | |
if QRencode::Util.black?(qr.data[x + qr.width * y]) | |
RGBA::BLACK | |
else | |
RGBA::WHITE | |
end | |
else | |
RGBA::WHITE | |
end | |
end | |
StumpyPNG.write(canvas, "test.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment