Project

qrest

0.0
No release in over a year
A Ruby library that generates QR Codes as XPM, SVG or EPS graphics.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Ruby-QRest

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.

Installation

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.)

Basic Usage

require "qrest"
qr = QRest::Code.new "https://example.com"
puts qr.to_s

Show it on the console:

design = {
  dark:       "\e[30;40mXX\e[m",
  light:      "\e[37;47m  \e[m",
  quiet_size: 4,
}
puts qr.to_s **design

If 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
end

Then open a new pane and say:

tmux save-buffer -

Pixel graphics

require "qrest/formats/xpm"
File.open "example.xpm", "w" do |f|
  qr.xpm pixels: 1, quiet_size: 2, output: f
end

For other formats, pipe the output to ImageMagick.

require "qrest/formats/xpm"
IO.popen [ "convert", "-", "example.png"], "w" do |p|
  qr.xpm output: p
end

Embedded PostScript

require "qrest/formats/eps"
File.open "example.eps", "w" do |f|
  qr.eps output: f
end

As PostScript images can freely be scaled, there is no such thing as a size or a dimension parameter.

SVG for Web pages

require "qrest/formats/svg"
File.open "example.svg", "w" do |f|
  qr.svg dimen: "132px", title: "example.com", id: "url_example", output: f
end

Here'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
end

Multiple Encoding Support

require "qrest"
qr = QRest::Code[
  {data: "299792458",        mode: "number"      },
  {data: "THX 1138",         mode: "alphanumeric"},
  {data: "tränenüberströmt", mode: "8bit"        },
]

Copyright

The word "QR Code" is a trademark of Denso Wave Inc..

Special thanks to: