Project

strokes

0.0
No commit activity in last 3 years
No release in over 3 years
Generates PNG images of barcodes. Currently supports EAN8, EAN13, QR-Code, ISBN, CODE39, CODE128, UPCA, UPCE, ITF
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

 Project Readme

Strokes

A ruby wrapper of the awesome postscriptbarcode library.

Note: currently only PNG images are supported.

External Dependencies

  • 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.

Install

Add it to your Gemfile

gem 'strokes'

or install the gem directly

gem install strokes

Usage

Using the gem directly

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)

Adding a barcode to your ActiveRecord model

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:

  1. code type: one of the supported code types or a method returning one of them
  2. code value: a method returning the value of the code
  3. versions: a hash of the versions to create, i.e. { :small => 200, :medium => 400 }