Code Monkey home page Code Monkey logo

rqrcode's Introduction

rQRCode, Encode QRCodes

Build Status

Short changelog

0.7.0 (Aug 15, 2015)

  • Added shape_rendering option for as_svg

0.6.0 (Jun 2, 2015)

  • Improved png rendering. Previous png rendering could result in hard to scan qrcodes. Big thanks to Bart Jedrocha

0.5.5 (Apr 25, 2015)

  • Fixed major bug. The rs block data was missing resulting in qr codes failing to be generated. Upgrade highly recomended!!

Overview

rQRCode is a library for encoding QR Codes in Ruby. It has a simple interface with all the standard qrcode options. It was adapted from the Javascript library by Kazuhiko Arase.

Let's clear up some rQRCode stuff.

  • rQRCode is a standalone library It requires no other libraries. Just Ruby!
  • It is an encoding library. You can't decode QR codes with it.
  • The interface is simple and assumes you just want to encode a string into a QR code
  • QR code is trademarked by Denso Wave inc

Installing

You may get the latest stable version from Rubygems.

gem install rqrcode

Using rQRCode

require 'rqrcode'

qrcode = RQRCode::QRCode.new("http://github.com/")
image = qrcode.as_png
svg = qrcode.as_svg
html = qrcode.as_html
string = qrcode.to_s

Image Rendering

SVG

The SVG renderer will produce a stand-alone SVG as a String

qrcode = RQRCode::QRCode.new("http://github.com/")
# With default options specified explicitly
svg = qrcode.as_svg(offset: 0, color: '000', 
                    shape_rendering: 'crispEdges', 
                    module_size: 11)

PNG

The library can produce a PNG. Result will be a ChunkyPNG::Image instance.

qrcode = RQRCode::QRCode.new("http://github.com/")
# With default options specified explicitly
png = qrcode.as_png(
          resize_gte_to: false,
          resize_exactly_to: false,
          fill: 'white',
          color: 'black',
          size: 120,
          border_modules: 4,
          module_px_size: 6,
          file: nil # path to write
          )

HTML Rendering

In your controller

@qr = RQRCode::QRCode.new( 'https://github.com/whomwah/rqrcode', :size => 4, :level => :h )

In your view

<%= raw @qr.as_html %>

CSS

table {
  border-width: 0;
  border-style: none;
  border-color: #0000ff;
  border-collapse: collapse;
}

td {
  border-left: solid 10px #000;
  padding: 0; 
  margin: 0; 
  width: 0px; 
  height: 10px; 
}

td.black { border-color: #000; }
td.white { border-color: #fff; }

On the console

qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
puts qr.to_s

Output:

xxxxxxx x  x x   x x  xx  xxxxxxx
x     x  xxx  xxxxxx xxx  x     x
x xxx x  xxxxx x       xx x xxx x
... etc 

Doing your own rendering

qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
qr.modules.each do |row|
    row.each do |col| 
        print col ? "X" : " "
    end
    print "\n"
end

API Documentation

http://www.rubydoc.info/gems/rqrcode

Resources

Authors

Original author: Duncan Robertson

Special thanks to the following people for submitting patches:

Contributing

  • Fork the project
  • Send a pull request
  • Don't touch the .gemspec, I'll do that when I release a new version

Copyright

MIT License (http://www.opensource.org/licenses/mit-license.html)

rqrcode's People

Contributors

gioele avatar whomwah avatar bjornblomqvist avatar clord avatar artfuldodger avatar nofxx avatar jekhor avatar bjedrocha avatar m0wfo avatar dasch avatar metaskills avatar lorddoig avatar sime avatar toretore avatar ferdinandrosario avatar

Watchers

James Cloos avatar Jose Luis Honorato avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.