Skip to content

Instantly share code, notes, and snippets.

@greenbigfrog
Last active December 19, 2018 21:48
Show Gist options
  • Save greenbigfrog/a642719523f451f021f20bdb3ebac3ba to your computer and use it in GitHub Desktop.
Save greenbigfrog/a642719523f451f021f20bdb3ebac3ba to your computer and use it in GitHub Desktop.
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
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