Readable QR codes in Terminal
# as of rqrcode 10.0 (Feb 2016), it can natively render ANSI making my code irrelevant: | |
require 'rubygems' | |
require 'rqrcode' | |
puts RQRCode::QRCode.new("http://www.example.com/").as_ansi |
# By: Pablo Averbuj - 2014/01/21 - Public Domain | |
require 'rubygems' | |
require 'rqrcode' # install this gem | |
require 'colorize' # install this gem | |
b = " ".colorize(:background => :black) | |
w = " ".colorize(:background => :white) | |
url = "http://www.google.com/" | |
# you may have to increase the :size parameter (and the w * 51 correspondingly) depending of the content you're encoding | |
qr = RQRCode::QRCode.new(url, :size => 8) | |
puts w * 51; qr.to_s(:true => b, :false => w).split("\n").each{|l| puts w + l + w } ; puts w * 51 |
# By: Pablo Averbuj - 2016/08/03 - Public Domain | |
# Modification with autosizing for URL | |
require 'rubygems' | |
require 'rqrcode' # install this gem | |
require 'colorize' # install this gem | |
def drawQR (url) | |
b = " ".colorize(:background => :black) | |
w = " ".colorize(:background => :white) | |
qr=nil | |
size=1 | |
while qr.nil? do | |
size += 1 | |
begin | |
qr = RQRCode::QRCode.new(url, :size => size) | |
puts w * (19+size*4); qr.to_s(:true => b, :false => w).split("\n").each{|l| puts w + l + w } ; puts w * (19+size*4) | |
rescue RQRCode::QRCodeRunTimeError | |
end | |
end | |
end | |
drawQR("http://www.google.com") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment