Skip to content

Instantly share code, notes, and snippets.

@harsh183
Created November 10, 2019 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harsh183/e3539c9d4b204aee44e066e6fc308c96 to your computer and use it in GitHub Desktop.
Save harsh183/e3539c9d4b204aee44e066e6fc308c96 to your computer and use it in GitHub Desktop.
require 'pry'
require 'rqrcode'
qrcode = RQRCode::QRCode.new('https://cs125.cs.illinois.edu')
png = qrcode.as_png(
bit_depth: 1,
border_modules: 4,
color_mode: ChunkyPNG::COLOR_GRAYSCALE,
color: 'black',
file: nil,
fill: 'white',
module_px_size: 6,
resize_exactly_to: false,
resize_gte_to: false,
size: 600
)
logo_size = 200
cs125_png = ChunkyPNG::Image.from_file('cs125.png')
cs125_png = cs125_png.resize(logo_size, logo_size)
png = png.compose(cs125_png, png.width/2 - logo_size/2, png.height/2 - logo_size/2)
# binding.pry
IO.write("/tmp/github-qrcode.png", png.to_s)
@harsh183
Copy link
Author

Quick and dirty approach but considering how noisy QR codes tend to be works decently well actually. Make sure to test your code before running with it, and perhaps then you can run a loop with it till it works. All this is pure ruby so

$ gem install rqrcode
$ ruby generate_qr_code.rb

Adapted parts from the rqrcode docs on RDoc, more helpful information available there.

@harsh183
Copy link
Author

harsh183 commented May 24, 2020

MIT License

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment