Skip to content

Instantly share code, notes, and snippets.

@uhlenbrock
Last active June 9, 2017 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uhlenbrock/bd0913be26a4ccc59e595ba507e4f41e to your computer and use it in GitHub Desktop.
Save uhlenbrock/bd0913be26a4ccc59e595ba507e4f41e to your computer and use it in GitHub Desktop.
Read Barcodes with a Dragonfly Analyzer
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
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