Giter Club home page Giter Club logo

zxing.rb's Introduction

ZXing

Decode QR codes (and other 1D/2D barcode formats)

QRcode generation is well served in the Ruby community, but decoding seems to be stuck in the Java world. This is an attempt to bridge the gap by wrapping the ZXing library with JRuby. ZXing conveniently decodes a plethora of barcodes. Their site has a complete list.

Installation

gem install zxing

Requirements

  • JRuby (tested with 1.5.6), OR

  • MRI (1.8.7 and 1.9.2) with jruby-jars gem

Usage

require 'zxing'

# Pass a path to a file, and it will return the characters encoded within
# the barcode image.  For example, if a QRCode image has the text "QRcode
# string" embedded:
ZXing.decode '/Users/ecin/qrcode.png' #=> "QRcode string"

# ZXing#decode_all returns an array of encoded values.  For example if an
# image has a barcode encoded with the value "test123" and another barcode
# encoded with the value "test456":
ZXing.decode_all 'image_with_multiple_barcodes.png' #=> ["test456", "test123"]

# You can also decode a URL...
ZXing.decode 'http://2d-code.co.uk/images/bbc-logo-in-qr-code.gif'

# or an instance of File
ZXing.decode File.new('qrcode.png')

# or anything that returns a URL or file path when #path is called on it.
class Image
  attr_reader :path
  def initialize(path); @path = path end
end

# ZXing#decode returns nil if it can't decode the image.
ZXing.decode 'image_without_a_code.png' #=> nil

# ZXing#decode! will raise an error if it can't decode the image.
ZXing.decode! 'image_without_a_code.png' #=> raises ZXing::UndecodableError

Decodable module

A Decodable module is included (pun intended) to ease using the library with objects that return the URL or file path to decode when #path or #to_s is called.

require 'zxing/decodable'

class File
  include Decodable
end

file = File.open('qrcode.png')
file.decode

zxing.rb's People

Contributors

ecin avatar jgdavey avatar guymaliar avatar wizman avatar

Watchers

James Cloos avatar  avatar Erez Alan Cohen avatar Hemdat avatar  avatar

Forkers

groony

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.