A library for generating QR Codes in pure and true Ruby.
Keep the classes small,
Methods short and readable.
Tests suites can't do that.
gem install qrest(In case you are using Neovim, you may like to execute the commands below inside the editor; please see Ruby-Nvim for an example.)
require "qrest"
qr = QRest::Code.new "https://example.com"
puts qr.to_sShow it on the console:
design = {
dark: "\e[30;40mXX\e[m",
light: "\e[37;47m \e[m",
quiet_size: 4,
}
puts qr.to_s **designIf you use Tmux you might prefer to do this in the editor:
IO.popen %w(tmux load-buffer -), "w" do |pipe|
pipe.puts qr.to_s **design
endThen open a new pane and say:
tmux save-buffer -require "qrest/formats/xpm"
File.open "example.xpm", "w" do |f|
qr.xpm pixels: 1, quiet_size: 2, output: f
endFor other formats, pipe the output to ImageMagick.
require "qrest/formats/xpm"
IO.popen [ "convert", "-", "example.png"], "w" do |p|
qr.xpm output: p
endrequire "qrest/formats/eps"
File.open "example.eps", "w" do |f|
qr.eps output: f
endAs PostScript images can freely be scaled, there is no such thing as a size or a dimension parameter.
require "qrest/formats/svg"
File.open "example.svg", "w" do |f|
qr.svg dimen: "132px", title: "example.com", id: "url_example", output: f
endHere's an example how to embed it into your HTML page:
require "qrest/formats/svg"
path = File.expand_path "~/public_html/example.html"
File.open path, "w" do |f|
qr.html output: f
endrequire "qrest"
qr = QRest::Code[
{data: "299792458", mode: "number" },
{data: "THX 1138", mode: "alphanumeric"},
{data: "tränenüberströmt", mode: "8bit" },
]- (C) 2025 Bertram Scharpf software@bertram-scharpf.de
- License: BSD-2-Clause+
- Repository: ruby-qrest
The word "QR Code" is a trademark of Denso Wave Inc..
Special thanks to: