forked from anujluthra/barcode-generator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
complete revamp of barcode generation, using gbarcode library. this a…
…llows for barcode generation in most of the prevelant formats. also provides for more control over the barcode image and its formatting.
- Loading branch information
1 parent
178455d
commit 6b41ddd
Showing
6 changed files
with
73 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,43 @@ | ||
BarcodeGenerator | ||
================ | ||
Author : Anuj Luthra | ||
Barcode generator makes generating/displaying bar-codes for certain alphanumeric ids a piece of cake. It uses free true-type barcode (code39) fonts and RMagick to create barcode images. | ||
Barcode generator makes generating/displaying bar-codes for certain | ||
alphanumeric ids a piece of cake. | ||
It uses Gbarcode for encoding barcode data and then rmagick to generate | ||
images out of it for displaying in views. | ||
|
||
This way we can generate any barcode type which Gbarcode -> Gnome Barcode project | ||
supports. | ||
|
||
USAGE: | ||
|
||
its as simple as saying | ||
<%= barcode 'FJJ4JD'%> | ||
and it will generate a barcode for FJJ4JD and include it in the view. | ||
the images are stored in /public/images/barcodes subdir. | ||
|
||
Installation: | ||
install from svn : http://barcode-generator.googlecode.com/svn/trunk/ | ||
and then run the rake task (rake barcode_setup) to create required dirs and installing the fonts ttf files in public dir. | ||
|
||
Barcode font (cod39) is a freeware and has been source from : http://www.barcodesinc.com/free-barcode-font/ | ||
according to its author Matthew Welch : | ||
---------------------------------------------------------------------- | ||
Free 3 of 9, like all of my fonts, is free. You can use it for most | ||
personal or business uses you'd like, and I ask for no money. I | ||
would, however, like to hear from you. If you use my fonts for | ||
something please send me a postcard or e-mail letting me know how | ||
you used it. Send me a copy if you can or let me know where I can | ||
find your work. | ||
This will generate a barcode for FJJ4JD in BARCODE_39 format with default width | ||
and height and include it in the view. | ||
the images are stored in /public/images/barcodes subdir. | ||
|
||
You may use this font for graphical or printed work, but you may not | ||
sell it or include it in a collection of fonts (on CD or otherwise) | ||
being sold. You can redistribute this font as long as you charge | ||
nothing to receive it. If you redistribute it include this text file | ||
with it as is (without modifications). | ||
Options Options Options .. | ||
|
||
If you use this font for commercial purposes please credit me in | ||
at least some little way. | ||
---------------------------------------------------------------------- | ||
to customize your barcodes, you can optionally pass following information in your views | ||
- encoding_format (Gbarcode constants for eg. Gbarcode::BARCODE_128 etc..) | ||
- width | ||
- height | ||
- scaling_factor | ||
- xoff | ||
- yoff | ||
- margin | ||
|
||
in this case your view will look like : | ||
<%= barcode 'ANUJ', :height => 100, | ||
:width => 400, | ||
:margin => 100, | ||
:xoff => 20, | ||
:yoff => 40 | ||
%> | ||
|
||
Installation: | ||
install from svn : http://barcode-generator.googlecode.com/svn/trunk/ | ||
make sure that you install gems for rmagick and gbarcode first!!! | ||
and then run the rake task : rake barcode_setup |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
|
||
BARCODE_COLUMNS = 200 | ||
BARCODE_ROWS = 100 | ||
BARCODE_POINTSIZE = 72 | ||
BARCODE_COLOR = 'black' | ||
ASTERISKIZE = true | ||
DEFAULT_ENCODING = Gbarcode::BARCODE_39 | ||
DEFAULT_FORMAT = 'PNG' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
# desc "Explaining what the task does" | ||
task :barcode_setup do | ||
require "ftools" | ||
Dir.mkdir("#{RAILS_ROOT}/public/images/barcodes", 0700) | ||
dirc = "#{RAILS_ROOT}/public/fonts/" | ||
Dir.mkdir( dirc , 0700 ) | ||
#opens/creates files | ||
font_file = 'FRE3OF9X.TTF' | ||
source = "#{RAILS_ROOT}/vendor/plugins/barcode_generator/fonts/#{font_file}" | ||
target = "#{dirc}#{font_file}" | ||
|
||
File.copy(source, target) | ||
puts "fonts file installed in public/fonts dir" | ||
puts "CREATED BARCODE DIR IN PUBLIC/IMAGES" | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,8 @@ | ||
require 'test/unit' | ||
|
||
class BarcodeGeneratorTest < Test::Unit::TestCase | ||
# Replace this with your real tests. | ||
|
||
def test_can_read_font_file | ||
assert File.exists?("#{RAILS_ROOT}/public/fonts/FRE3OF9X.TTF"), 'could not locate font file. Please run the rake task barcode_setup' | ||
end | ||
|
||
def test_can_create_barcode_image | ||
image_path = ActionView::Base.barcode('test') | ||
assert File.exists?("#{RAILS_ROOT}/public/images/#{image_path}"), 'barcode not generated' | ||
end | ||
assert(true) | ||
end | ||
end |