A ruby wrapper of the awesome postscriptbarcode library.
Note: currently only PNG images are supported.
- You need to have ghostscript installed and the
gs
command in your PATH. - You also need the
mogrify
command in your PATH, which is part of the imagemagick library.
Add it to your Gemfile
gem 'strokes'
or install the gem directly
gem install strokes
require 'strokes'
code = Strokes::Barcode.new(:qrcode, 'http://github.com/larskuhnt/strokes')
code.save('/tmp/test.png')
# if you want to resize the image to a width of 200 pixels
code.save('/tmp/test.png', :width => 200)
Barcodes including text will be a bit blurry after resizing (if you have an idea how to fix that, I will be glad for your input)
It's as easy as:
require 'strokes'
require 'strokes/active_record'
class Barcode < ActiveRecord::Base
include Strokes::ActiveRecord
has_barcode :isbn, :isbn_number, { :small => 200, :medium => 400 }
end
It will generate three ISBN barcode images in the directory
#{Rails.root}/barcodes/#{self.class.to_s.tableize}
,
the original sized image and the specified versions with 200 and 400 pixels width.
The parameters for the has_barcode
method are:
- code type: one of the supported code types or a method returning one of them
- code value: a method returning the value of the code
- versions: a hash of the versions to create, i.e.
{ :small => 200, :medium => 400 }