Skip to content

smparkes/zxing.rb

Repository files navigation

THIS IS A REAL WORK IN PROGRESS

I use this stuff on a regular basis to test zxing but I haven’t had time to cleanup all the gem stuff in order to install it as a gem, particularly with all the various VM stuff and dynamic linking. For example, it currently uses scons to build the C++ directory. Translating that to ruby so as not not to require python would be nice but seems tricky, at least for me.

If you have the time to contribute improvements in any of these (or other areas), they’re welcome.

I tried to make the interface compatible with the ecin’s zxing gem but I’m not sure how complete that is right now. I don’t use it, so …

zxing.rb

DESCRIPTION:

zxing.rb is a Ruby interface to the ZXing barcode library.

FEATURES:

  • Supports ZXing Java under jruby

  • Supports ZXing C++ under ruby 1.8 and 1.9

I’ve played with MacRuby but it was a while ago and I don’t think I ever integrated that support with this (proto)gem.

SUPPORT:

The bug tracker is available here:

http://github.com/smparkes/zxing.rb/issues

SYNOPSIS:

require 'zxing'
result = ZXing.decode "myimage.png"

zxing.rb also comes with a command that decodes images: zxd:

$ zxd filename.png
<decoded contents>

zxd can take multiple arguments and the arguments can be URLs.

zxing.rb provides access to many of the classes of ZXing classes like readers, luminance sources, binarizers, so you can mix and match your own applications much as you would with a native Java or C++ app. See zxd and test/vendor.rb for examples.

There is a proto-encoder (zxe) but I don’t think it’s hooked up. I thought it was at some point, but …

Using the ZXing module

require 'zxing'

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

# ... or a file path...
ZXing.decode '/Users/ecin/qrcode.png'

# ... or a File object...
ZXing.decode File.open('qrcode.png')

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

image = Image.new('qrcode.png')
ZXing.decode image

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

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

# Feel free to include ZXing to shorten the call.
include ZXing

decode 'qrcode.png'

Including the Decodable module

require 'zxing/decodable'

class File
  include Decodable
end

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

REQUIREMENTS:

  • Ruby 1.8, 1.9, or jruby

  • rmagick on ruby 1.8/1.9

zxing.rb bundles a version of zxing.

INSTALL:

The gem packaging is incomplete. For now, you need to clone the repo, get zxing as a submodule (git submodule update –init) and then you can build and run the tests.

On Mac OS X, you may run into a issue when you run the build:

ld: warning: ignoring file zxing.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: ignoring file [path]/zxing.rb/vendor/zxing/cpp/build/libzxing.a, file was built for archive which is not the architecture being linked (i386)

To get a successful build in this case, invoke rake setting the ARCHFLAGS environment variable:

rake clean
ARCHFLAGS="-arch x86_64" rake

DEVELOPMENT:

rake test && rake zxing:test

rake test runs the zxing.rb unit tests. rake zxing:test runs the standard ZXing blackbox tests. You can give rake zxing:test a parameter to only run matching tests (based on file globing). For example, rake zxing:test[qrcode-2/1] will run the qrcode tests in set 2 that start with 1 (1, 10, 11, etc.)

LICENSE:

(The MIT License)

Copyright © 2011 Steven Parkes

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

A ruby interface to zxing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published