Skip to content

Instantly share code, notes, and snippets.

@citrus
Created December 5, 2011 17:52
Show Gist options
  • Save citrus/1434552 to your computer and use it in GitHub Desktop.
Save citrus/1434552 to your computer and use it in GitHub Desktop.
require 'rqrcode'
require 'erb'
text = ARGV.shift
if text.nil?
puts "Please supply some text.."
exit
end
css = <<CSS
<style type="text/css">
table {
margin: 25px auto;
border-width: 0;
border-style: none;
border-color: #0000ff;
border-collapse: collapse;
}
td {
border-width: 0;
border-style: none;
border-color: #0000ff;
border-collapse: collapse;
padding: 0;
margin: 0;
width: 5px;
height: 5px;
}
td.black { background-color: #000; }
td.white { background-color: #fff; }
</style>
CSS
html = <<HTML
<table>
<% @qr.modules.each_index do |x| %>
<tr>
<% @qr.modules.each_index do |y| %>
<% if @qr.dark?(x,y) %>
<td class="black"/>
<% else %>
<td class="white"/>
<% end %>
<% end %>
</tr>
<% end %>
</table>
HTML
@qr = RQRCode::QRCode.new(text)
erb = ERB.new(html)
out = [ css, erb.result(binding) ].join
File.open(File.expand_path("../qr.html", __FILE__), 'w') {|f| f.write out }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment