Last active
June 9, 2017 19:37
-
-
Save uhlenbrock/bd0913be26a4ccc59e595ba507e4f41e to your computer and use it in GitHub Desktop.
Read Barcodes with a Dragonfly Analyzer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BarcodeAnalyser | |
def call(app, opts = {}) | |
# OS X: `brew install zbar` | |
# Ubuntu: `apt-get install zbar-tools` | |
app.env[:zbar_command] = opts[:zbar_command] || 'zbarimg' | |
app.define :barcode do | |
@barcode ||= begin | |
shell_eval { |path| "#{app.env[:zbar_command]} -q --raw #{path}" } | |
rescue Dragonfly::Shell::CommandFailed => e | |
Dragonfly.debug(e) | |
nil | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dragonfly' | |
require 'barcode_analyzer' | |
Dragonfly.app.configure do | |
plugin BarcodeAnalyser.new | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment