Skip to content

BertramScharpf/ruby-qrest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

About

A QR Code generator in Ruby

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors