Giter Site home page Giter Site logo

rqrcode's Introduction

RQRCode

RQRCode is a library for creating and rendering QR codes into various formats. It has a simple interface with all the standard QR code options. It was adapted from the Javascript library by Kazuhiko Arase.

  • QR code is trademarked by Denso Wave inc
  • Minimum Ruby version is ~> 2.3
  • For rqrcode releases < 1.0.0 please use this README

Installing

Add this line to your application's Gemfile:

gem 'rqrcode'

or install manually:

gem install rqrcode

Basic usage example

require 'rqrcode'

qr = RQRCode::QRCode.new('http://github.com')
result = ''

qr.qrcode.modules.each do |row|
  row.each do |col|
    result << (col ? 'X' : 'O')
  end

  result << "\n"
end

puts result

Advanced Options

These are the various QR Code generation options provided by rqrqcode_core.

string - the string you wish to encode

size   - the size of the qrcode (default 4)

level  - the error correction level, can be:
  * Level :l 7%  of code can be restored
  * Level :m 15% of code can be restored
  * Level :q 25% of code can be restored
  * Level :h 30% of code can be restored (default :h)

mode   - the mode of the qrcode (defaults to alphanumeric or byte_8bit, depending on the input data):
  * :number
  * :alphanumeric
  * :byte_8bit
  * :kanji

Example

qrcode = RQRCodeCore::QRCode.new('hello world', size: 1, level: :m, mode: :alphanumeric)

Render types

You can output your QR code in various forms. These are detailed below:

as SVG

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

require 'rqrcode'

qrcode = RQRCode::QRCode.new("http://github.com/")

# NOTE: showing with default options specified explicitly
svg = qrcode.as_svg(
  offset: 0,
  color: '000',
  shape_rendering: 'crispEdges',
  module_size: 6,
  standalone: true
)

QR code with github url

as ANSI

The ANSI renderer will produce as a string with ANSI color codes.

require 'rqrcode'

qrcode = RQRCode::QRCode.new("http://github.com/")

# NOTE: showing with default options specified explicitly
svg = qrcode.as_ansi(
  light: "\033[47m", dark: "\033[40m",
  fill_character: '  ',
  quiet_zone_size: 4
)

QR code with github url

as PNG

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

require 'rqrcode'

qrcode = RQRCode::QRCode.new("http://github.com/")

# NOTE: showing with default options specified explicitly
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: 120
)

IO.binwrite("/tmp/github-qrcode.png", png.to_s)

QR code with github url

On the console ( just because you can )

require 'rqrcode'

qr = RQRCode::QRCode.new('http://kyan.com', size: 4, level: :h)

puts qr.to_s

Output:

xxxxxxx   x x  xxx    xxxxxxx
x     x  xxxxx  x x   x     x
x xxx x    x x     x  x xxx x
x xxx x  xxx  x xxx   x xxx x
x xxx x xxx  x  x  x  x xxx x
... etc

API Documentation

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

Tests

You can run the test suite using:

$ ./bin/setup
$ bundle exec rspec

or try the lib from the console with:

$ ./bin/console

Contributing

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

Authors

Original RQRCode author: Duncan Robertson

A massive thanks to all the contributors of the library over the years. It wouldn't exist if it wasn't for you all.

Oh, and thanks to my bosses at https://kyan.com for giving me time to maintain this project.

Resources

Copyright

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

rqrcode's People

Contributors

whomwah avatar bjornblomqvist avatar gioele avatar fabn avatar clord avatar jekhor avatar nofxx avatar lmmendes avatar artfuldodger avatar ab avatar thiaguerd avatar nickgnd avatar ferdinandrosario avatar toretore avatar thbar avatar sime avatar lorddoig avatar pocke avatar rezigned avatar metaskills avatar dasch avatar m0wfo avatar berkes avatar bjedrocha 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.