Giter Club home page Giter Club logo

barby's Introduction

Barby

Barby is a Ruby library that generates barcodes in a variety of symbologies.

Its functionality is split into barcode and "outputter" objects:

  • [Barby::Barcode objects] symbologies turn data into a binary representation for a given symbology.
  • [Barby::Outputter] outputters then takes this representation and turns it into images, PDF, etc.

You can easily add a symbology without having to worry about graphical representation. If it can be represented as the usual 1D or 2D matrix of lines or squares, outputters will do that for you.

Likewise, you can easily add an outputter for a format that doesn't have one yet, and it will work with all existing symbologies.

For more information, check out the Barby wiki.

New require policy

Barcode symbologies are no longer required automatically, so you'll have to require the ones you need.

If you need EAN-13, require 'barby/barcode/ean_13'. Full list of symbologies and filenames below.

Example

require 'barby'
require 'barby/barcode/code_128'
require 'barby/outputter/ascii_outputter'

barcode = Barby::Code128B.new('BARBY')

puts barcode.to_ascii #Implicitly uses the AsciiOutputter

## #    #  #   # ##   # #   ##   ##   # ### #   # ##   ### ## #   ## ### ### ##   ### # ##
## #    #  #   # ##   # #   ##   ##   # ### #   # ##   ### ## #   ## ### ### ##   ### # ##
## #    #  #   # ##   # #   ##   ##   # ### #   # ##   ### ## #   ## ### ### ##   ### # ##
## #    #  #   # ##   # #   ##   ##   # ### #   # ##   ### ## #   ## ### ### ##   ### # ##
## #    #  #   # ##   # #   ##   ##   # ### #   # ##   ### ## #   ## ### ### ##   ### # ##
## #    #  #   # ##   # #   ##   ##   # ### #   # ##   ### ## #   ## ### ### ##   ### # ##
## #    #  #   # ##   # #   ##   ##   # ### #   # ##   ### ## #   ## ### ### ##   ### # ##
## #    #  #   # ##   # #   ##   ##   # ### #   # ##   ### ## #   ## ### ### ##   ### # ##
## #    #  #   # ##   # #   ##   ##   # ### #   # ##   ### ## #   ## ### ### ##   ### # ##
## #    #  #   # ##   # #   ##   ##   # ### #   # ##   ### ## #   ## ### ### ##   ### # ##
          B          A          R          B          Y

Supported symbologies

require 'barby/barcode/<filename>'
Name Filename Dependencies
Code 25 code_25
├─ Interleaved code_25_interleaved
└─ IATA code_25_iata
Code 39 code_39
└─ Extended code_39
Code 93 code_93
Code 128 (A, B, and C) code_128
└─ GS1 128 gs1_128
Codabar codabar
EAN-13 ean_13
├─ Bookland bookland
└─ UPC-A ean_13
EAN-8 ean_8
UPC/EAN supplemental, 2 & 5 digits upc_supplemental
QR Code qr_code rqrcode
DataMatrix (Semacode) data_matrix semacode or semacode-ruby19
PDF417 pdf_417 JRuby

Outputters

require 'barby/outputter/<filename>_outputter'
filename dependencies
ascii
cairo cairo
html
pdfwriter
png chunky_png
prawn prawn
rmagick rmagick
svg

Formats supported by outputters

  • Text (mostly for testing)
  • PNG, JPEG, GIF
  • PS, EPS
  • SVG
  • PDF
  • HTML

For more information, check out the Barby wiki.

barby's People

Contributors

amatsuda avatar ar31an avatar aslakhellesoy avatar benbruscella avatar chinasaur avatar domribaut avatar dra1n avatar firedev avatar gleseur avatar heliocola avatar jamesbrink avatar joseramonc avatar joshuaflanagan avatar labocho avatar mariusbutuc avatar metaskills avatar nashirox avatar orange-kao avatar philayres avatar stlewis avatar stuxcrystal avatar toretore avatar troessner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

barby's Issues

Automatically choosing Code128 subset

Would you be open to a pull request which enables Barby to choose the subset of Code128 which results in the narrowest barcode width for the data?

I'm thinking something like:

barcode = Barby::Code128Auto.new(data)

or:

barcode = Barby::Code128.for_data(data)

The logic would first see whether subset C is valid for the data; if not, it would try B; finally it would fall back to A.

uninitialized constant Barby::CairoOutputter

Hi. I have rails 4.1 and ruby 2.1 installed. Installed gem barby and could not make it work. The require cairo gives me an error that could not load such file. And if I remove the require, gives me the error uninitialized constant Barby::CairoOutputter

Can anyone help me with this ?

Issue with barcode

Hi,

I've added information to #54 after implementing your code to no avail. The UPC generated is still different than the stock image distributed (or generated) on sites available on the internet.

barcode image tag

I wrote a simple method that can create an image tag in rails for a barcode based on a requested width and height. Is this something that would make sense in barby?

    def barcode_image_tag(text, height:, width:, margin: 10)
      barcode = Barby::Code39.new(text.to_s)

      # How wide should the bar be so that it best fills the requested image width?
      xdim = (width.to_f / barcode.encoding.length).round

      image = barcode.to_image(
        xdim: xdim * 2, # double resolution for clearer printed image (and retina)
        margin: margin,
        height: (height - margin) * 2 # Barby expects height without top/bottom margin.
      )

      # Now use the official height and width of the image rather than stretch it.
      image_tag(
        image.to_data_url,
        width: image.width / 2,
        height: image.height / 2,
        alt: text.to_s
      )
    end

If this steps outside of the scope of this gem, feel free to close this.

Barcode does not print numbers below barcode

`
APPLICATION CONTROLLER

class ApplicationController < ActionController::Base
require 'chunky_png'
require 'barby'
require 'barby/barcode/ean_13'
require 'barby/outputter/png_outputter'

def barcode_output(barstring)
barcode_string = barstring.to_s.rjust(12,"0")
barcode = Barby::EAN13.new(barcode_string)

# PNG OUTPUT
data           = barcode.to_image(height: 40, margin: 10).to_data_url

end
end

ACTION
class ClientsController < ApplicationController

def clientlist
@Clients = Client.all
@barcode = barcode_output('1234567')
respond_to do |format|
format.html
format.pdf do
render pdf: "clientlist",
template: 'clients/clientlist.html.erb',
show_as_html: params[:debug].present?,
locals: { :clients => @Clients },
outline: { outline: true,
outline_depth: 50 },
margin: { top: 10, # default 10 (mm)
bottom: 10,
left: 10,
right: 10 }
end
end
end

CLIENTLIST.HTML.ERB

Clients BARCODE



"<%= wicked_pdf_image_tag_for_public(@barcode) %>

`

barcode on console

Hallo, I made a minifunction to bring the barcode to an console, so that my smartphone also recognized this, maybe you can use this method.

deadspace is the space around the barcode
spaces is the sign that will used as space

Bye - and thanks for barby
PS: the backslash are difficult to write here

require 'barby'
require 'barby/outputter/ascii_outputter
str="Hallo Barby"
bc=Barby::QrCode.new(str,:level=>:l)

def to_graph(bc,deadspace=3,spaces="\333")
a = bc.to_ascii(:bar=>" ",:space=>spaces).split(/\n/)
dim = a[0].size
deadspace.times{a.unshift(spaces_dim)}
deadspace.times{a.push(spaces_dim)}
return a.map{|i| i=spaces_deadspace+i+spaces_deadspace}.join("\n")
end

puts to_graph(bc)

Undefined method nil.rszf

In irb

>> data = "2 1058 657682"
>> barcode = Barby::QrCode.new(data)
>> File.open('barcode.png', 'w+') 
{|f| f.write barcode.to_png(:height => 100, :margin => 25, :xdim => 100) }

Generates error:

ActionView::TemplateError (/Library/Ruby/Gems/1.8/gems/barby-    0.4.0/vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:296:in `map_data': You have a nil     object when you didn't expect it!
The error occurred while evaluating nil.rszf) on line #1 of app/views/profile/ticket.rpdf:
1: pdf.font_families["Helvetica"] =
2: {
3:   "b"   => "Helvetica-Bold",
4:   "i"   => "Helvetica-Oblique"    
lib/pdf_render.rb:46:in `pdf'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:291:in `each'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:291:in `map_data'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:287:in `step'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:287:in `map_data'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:172:in `make_impl'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:196:in `get_best_mask_pattern'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:195:in `each'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:195:in `get_best_mask_pattern'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:145:in `make'
barby (0.4.0) vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb:85:in `initialize'
barby (0.4.0) lib/barby/barcode/qr_code.rb:94:in `new'
barby (0.4.0) lib/barby/barcode/qr_code.rb:94:in `rqrcode'
barby (0.4.0) lib/barby/barcode/qr_code.rb:55:in `encoding'
barby (0.4.0) lib/barby/outputter.rb:86:in `encoding'
barby (0.4.0) lib/barby/outputter/png_outputter.rb:67:in `height'
barby (0.4.0) lib/barby/outputter.rb:116:in `send'
barby (0.4.0) lib/barby/outputter.rb:116:in `with_options'
barby (0.4.0) lib/barby/outputter.rb:114:in `each'
barby (0.4.0) lib/barby/outputter.rb:114:in `inject'
barby (0.4.0) lib/barby/outputter.rb:114:in `with_options'
barby (0.4.0) lib/barby/outputter/png_outputter.rb:18:in `to_canvas'
barby (0.4.0) lib/barby/outputter/png_outputter.rb:58:in `to_png'
barby (0.4.0) lib/barby/barcode.rb:70:in `send'
barby (0.4.0) lib/barby/barcode.rb:70:in `method_missing'
(eval):107:in `pdf'
(eval):88:in `each'
(eval):88:in `pdf'
lib/pdf_render.rb:18:in `eval'
lib/pdf_render.rb:46:in `pdf'
lib/pdf_render.rb:18:in `render'

...

Whereas if I change data to "2 1058 657681" (replace the final '2' for a '1') it works fine.

Gems:

barby 0.4.0
png 1.1.0 (1.2.0 kept getting String::CompilationError)

Releasing a new version

Hello,

Are there any plans to release a newer version of the gem?
I noticed that 0.60 introduces code128 barcode length optimizations, which is exactly what I'm looking for at the moment. 😃

The latest available gem is 0.5.1, which I am currently using.

Thanks!

Ruby 2.0.0 compatibility

It looks like barby is falling prey to the Ruby 2.0.0 switch from default character encoding ASCII-8BIT to UTF-8.

In particular, at least lib/barby/barcode/code_128.rb:210

The CODE* constants have UTF-8 encoding in ruby 2.0.0, and through details I don't fully understand this generates a RegexpError: "/.../n has a non escaped non ASCII character in non ASCII-8BIT script"

Console log:

[30] pry(main)> Barby::Code128B::CODEA.encoding
=> #<Encoding:UTF-8>
[31] pry(main)> /#{Barby::Code128B::CODEA}/n
RegexpError: /.../n has a non escaped non ASCII character in non ASCII-8BIT script
from (pry):26:in `__pry__'
[32] pry(main)> /#{Barby::Code128B::CODEA}/
ArgumentError: invalid multibyte character
from (pry):27:in `__pry__'
[33] pry(main)> Barby::Code128B::CODEA.force_encoding 'ASCII-8BIT'
=> "\xC5"
[34] pry(main)> /#{Barby::Code128B::CODEA}/n
=> /\xC5/n
[35] pry(main)> /#{Barby::Code128B::CODEA}/
=> /\xC5/
[36] pry(main)> .ruby --version
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]
[37] pry(main)> .gem list barby

*** LOCAL GEMS ***

barby (0.5.0)
[38] pry(main)> 

I've been thinking about a patch, but not sure the best route to go.
Force encodings everywhere? Don't use //n ?
I don't grok barcode encodings well enough to understand what's a fix and what's a break :-)

barby css doesnt work in chrome browser

Hi,

I've found out that the standard css code doesnt work in Chrome. Barcodes even look different when compared. In Firefox the barcodes are recognized well with a scanner.

table.barby-barcode { border-spacing: 0; }
tr.barby-row {}
td.barby-cell { width: 3px; height: 3px; }
td.barby-cell.on { background: #000; }

I use 'barby/barcode/code_128' with HTMLOutputter

PNG barcode doesn't print cleanly

I'm generating a PNG from the barcode, but when it's printed the barcode lines aren't clean. I printed other barcodes I got elsewhere that are the same size and they print very clean and crisp. Is this an issue with the barcode generator or png outputter, or ...? Sorry if this isn't doesn't turn out to be an issue specifically with this gem.

    barcode = Barby::Code128A.new(@product.fnsku)
    outputter = Barby::PngOutputter.new(barcode)
    barcode = 'app/assets/images/barcode.png'
    File.open(barcode, 'w'){|f| f.write outputter.to_png }

encoding issue

I have my db and ruby set to utf-8 (ascii doesn't diplay our language)

Now i'm getting an exception:
Encoding::CompatibilityError (incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string)):

here:
barby-0.6.2/lib/barby/barcode/code_128.rb:221:in split' barby-0.6.2/lib/barby/barcode/code_128.rb:221:indata='

So the data seems my string (utf-8) and the regex is from that file, which is coded ascii.

I'm still investigating as to how this can be avoided, just thought i'll let you know.

Barby::QrCode does not implement valid? method

Therefore any calls to validate Barby::QrCode will always return false since this is the default value of the base class Barby::Barcode.

Reproduction:
barcode = Barby::QrCode.new('1234567890')
barcode.valid? == false

All of the other Symbologies implement valid? method. I think that QrCode should too.

Screen scanners do not read Code39

First of all thanks for creating barby library. We use it quite often. However we've encountered a problem using it.

Screen scanners like Motorola MC9190 don't read barby-generated Code 39 barcodes. It didn't matter what outputter we used. We've checked PNG, GIF, PDF, etc. and it worked 1 time for every 10 attempts. We had to switch some JS library and it is working perfect.

Maybe it's the problem with lines thickness that does not appears on printed barcodes.

Encoding::UndefinedConversionError: "\x89" from ASCII-8BIT to UTF-8

Abstract

Error recorded in production server trying to create a bar-code. Is this a bug in the lib or some thing we are doing wrong? Thanks in advance.

Details

The bar-code creation process works fine, but last night Rollbar had recorded an error. We are using v0.6.3 and the error received is as follows.

  • Version 0.6.3
  • Order ID = 1145
require 'barby'
require 'barby/barcode/code_128'
require 'barby/outputter/ascii_outputter'
require 'barby/outputter/png_outputter'

class Admin::OrdersController < AdminController
  def print
    @order = Order.find(params[:id])
    @order_id = sprintf '%010d', @order.id                                                                                                        

   @barcode = Barby::Code128B.new(@order_id) 
    bar_code_image_path  = Rails.root.join('public/bar_codes',"#{@order.id}.png" )                                                                
    File.open(bar_code_image_path , 'w'){|f|
      f.write @barcode.to_png(:height => 50, :margin => 15) # The line which the error happens                                                                                      
    }

    render layout: 'print'
end

Resulting error

Encoding::UndefinedConversionError: "\x89" from ASCII-8BIT to UTF-8
1 File "/home/rails/production/releases/20160506183304/app/controllers/admin/orders_controller.rb" line 79 in write
2 File "/home/rails/production/releases/20160506183304/app/controllers/admin/orders_controller.rb" line 79 in block in print
3 File "/home/rails/production/releases/20160506183304/app/controllers/admin/orders_controller.rb" line 78 in open
4 File "/home/rails/production/releases/20160506183304/app/controllers/admin/orders_controller.rb" line 78 in print

Barcode numbers?

I am currently using the Barby::PrawnOutputter to insert the generated barcodes straight into a pre-existing Prawn PDF file. However, I'd like to ensure that EAN8, EAN13 & Code 128 barcodes also have the numbers beneath them as per their "usual" form.

Is there a way to do this in Barby?

rubygem.org doesn't seem to have latest code

For example, when I pull 0.5.1 from rubygem, the html_outputter.rb is old - whereas the gemspec in this github is still at 0.5.0 and the html_outputter.rb has been re-written.

Porting to rails 3.2.8

Hi I was using rails 2.3.5 and ruby 1.8.7 and barby was working fine.
Now I am porting my application to rails 3.2.8 and ruby 1.9.2p180 and from barby 0.4.2 to 0.5.0
This is part of my code:

require 'barby'
require 'barby/barcode/code_128'
require 'barby/outputter/rmagick_outputter'

def barcode(path,i,h,m,x)
barcode = Barby::Code128B.new("#{i}")

File.open(path, 'w') do |f|
f.write barcode.to_jpg(:height => h, :margin => m, :xdim => x)
end
end

when it reaches barcode = Barby::Code128B.new("#{i}"), it throws the exception
RegexpError (/.../n has a non escaped non ASCII character in non ASCII-8BIT script)

doing some research it seems it is related to encode, perhaps barby needs some kind of update ??

Could you, please let me know you thoughts about that.
Thanks a lot,

Fernando

Barcode value not displayed below bars

On the README page the ascii barcode shows the value in text below the bar code. (I'd say this is the norm for most barcode applications, incase the scanner is unable to read the bars). But the bar codes I've generated with to_png and to_ascii don't show the values below the bars. For example:

    ## #  #    # ##    #  #    #  ## #    # ##  #  ###  ## ### #  ##  ###  # ##  # ##    #  ### ## ### ##  #  ### ### #   ## ##   ### # ##
    ## #  #    # ##    #  #    #  ## #    # ##  #  ###  ## ### #  ##  ###  # ##  # ##    #  ### ## ### ##  #  ### ### #   ## ##   ### # ##
    ## #  #    # ##    #  #    #  ## #    # ##  #  ###  ## ### #  ##  ###  # ##  # ##    #  ### ## ### ##  #  ### ### #   ## ##   ### # ##
    ## #  #    # ##    #  #    #  ## #    # ##  #  ###  ## ### #  ##  ###  # ##  # ##    #  ### ## ### ##  #  ### ### #   ## ##   ### # ##
    ## #  #    # ##    #  #    #  ## #    # ##  #  ###  ## ### #  ##  ###  # ##  # ##    #  ### ## ### ##  #  ### ### #   ## ##   ### # ##
    ## #  #    # ##    #  #    #  ## #    # ##  #  ###  ## ### #  ##  ###  # ##  # ##    #  ### ## ### ##  #  ### ### #   ## ##   ### # ##
    ## #  #    # ##    #  #    #  ## #    # ##  #  ###  ## ### #  ##  ###  # ##  # ##    #  ### ## ### ##  #  ### ### #   ## ##   ### # ##
    ## #  #    # ##    #  #    #  ## #    # ##  #  ###  ## ### #  ##  ###  # ##  # ##    #  ### ## ### ##  #  ### ### #   ## ##   ### # ##
    ## #  #    # ##    #  #    #  ## #    # ##  #  ###  ## ### #  ##  ###  # ##  # ##    #  ### ## ### ##  #  ### ### #   ## ##   ### # ##
    ## #  #    # ##    #  #    #  ## #    # ##  #  ###  ## ### #  ##  ###  # ##  # ##    #  ### ## ### ##  #  ### ### #   ## ##   ### # ##

I'm using ruby 1.9.2, and have barby setup like:

  require 'barby'
  require 'barby/outputter/png_outputter'
  require 'barby/outputter/ascii_outputter'

  def barcode_ascii
    barcode = Barby::Code128B.new(self.my_barcode_value)
    barcode.to_ascii
  end

`

Have I missed an option, or if I want the code value to display under the bars I need to implement that?

Prawn v1.x compatibility

I could be wrong, but I believe that the prawn_outputter no longer works correctly with the current stable / release version of PrawnPDF v1.1.0? It was all working fine but it seems to not output anything now when I attempt to use annotate_pdf

PngOutputter seems to ignore images dimensions.

I am using Barby 0.5.1 with chunky_png 1.2.8.

require 'RMagick'
include Magick
require 'barby'
require 'barby/barcode/code_128'
require 'barby/outputter/png_outputter'

def draw_barcode2(id, options = {})
  barcodes_dir = FileUtils.mkdir_p("/Users/kasper/projects/barcoda/barcodes")
  filepath = File.join(barcodes_dir, "#{id}")
  filepath = "#{filepath}-rotated" if options[:rotate]
  filepath = "#{filepath}.png"

  barcode = Barby::Code128B.new(id)
  File.open(File.join(filepath), 'w') do |f|
      f.write barcode.to_image(:margin => 0,
                               :height => options[:height],
                               :width  => options[:width])
  end
end

I then run it as:

puts draw_barcode2('1-4-019', :width => 70, :height => 260, :rotate => true)
puts draw_barcode2('1-4-019', :width => 70, :height => 260, :rotate => false)
puts draw_barcode2 '1-4-021', :width => 280, :height => 70

puts draw_barcode2('1-4-020', :width => 70, :height => 260, :rotate => true)
puts draw_barcode2('1-4-020', :width => 70, :height => 260, :rotate => false)
puts draw_barcode2 '1-4-021', :width => 280, :height => 70

# Retina:
puts draw_barcode2 '1-4-022', :width => 560, :height => 120

But the result is this:

[barcodes (master)]=> sips -g pixelHeight -g pixelWidth *
/Users/kasper/projects/barcoda/barcodes/1-4-019-rotated.png
  pixelHeight: 70
  pixelWidth: 112
/Users/kasper/projects/barcoda/barcodes/1-4-019.png
  pixelHeight: 70
  pixelWidth: 112
/Users/kasper/projects/barcoda/barcodes/1-4-020-rotated.png
  pixelHeight: 70
  pixelWidth: 112
/Users/kasper/projects/barcoda/barcodes/1-4-020.png
  pixelHeight: 70
  pixelWidth: 112
/Users/kasper/projects/barcoda/barcodes/1-4-021.png
  pixelHeight: 70
  pixelWidth: 112
/Users/kasper/projects/barcoda/barcodes/1-4-022.png
  pixelHeight: 70
  pixelWidth: 112

Am I using the library wrong, or is this a bug?

EAN13.rb said to handle UPC-A but it requires 12 digits passed

I padded the number to be represented with the arcode to 12 diits with 0's on left, and it was readable by a UPC-A reader and identified as UPC-A but that was one test. Did I handle this in the correct way?

 def barcode_output(barstring)
    barcode_string = barstring.to_s.rjust(12,"0")
    barcode        = Barby::EAN13.new(barcode_string)
  
    # PNG OUTPUT
    data           = barcode.to_image(height: 40, margin: 10).to_data_url

Exception in generating QR code with Japanese and Chinese character

Exception in generating QR code with Japanese and Chinese character in barby-0.6.3 and rqrcode-0.10.1

Code

#!/usr/bin/env ruby
# encoding: utf-8

require 'barby'
require 'barby/barcode/qr_code'
require 'barby/outputter/png_outputter'

data = "おはようございます早安"

barcode = Barby::QrCode.new(data)
File.open("barby-test.png", "w"){|file|
  file.write barcode.to_png
}

Output

$ ./barby-test 
/home/orange/.gem/ruby/2.0.0/gems/rqrcode-0.10.1/lib/rqrcode/qrcode/qr_code.rb:514:in `create_data': code length overflow. (276>152). (Try a larger size!) (RQRCode::QRCodeRunTimeError)
    from /home/orange/.gem/ruby/2.0.0/gems/rqrcode-0.10.1/lib/rqrcode/qrcode/qr_code.rb:337:in `make_impl'
    from /home/orange/.gem/ruby/2.0.0/gems/rqrcode-0.10.1/lib/rqrcode/qrcode/qr_code.rb:369:in `block in get_best_mask_pattern'
    from /home/orange/.gem/ruby/2.0.0/gems/rqrcode-0.10.1/lib/rqrcode/qrcode/qr_code.rb:368:in `each'
    from /home/orange/.gem/ruby/2.0.0/gems/rqrcode-0.10.1/lib/rqrcode/qrcode/qr_code.rb:368:in `get_best_mask_pattern'
    from /home/orange/.gem/ruby/2.0.0/gems/rqrcode-0.10.1/lib/rqrcode/qrcode/qr_code.rb:313:in `make'
    from /home/orange/.gem/ruby/2.0.0/gems/rqrcode-0.10.1/lib/rqrcode/qrcode/qr_code.rb:232:in `initialize'
    from /home/orange/.gem/ruby/2.0.0/gems/barby-0.6.3/lib/barby/barcode/qr_code.rb:95:in `new'
    from /home/orange/.gem/ruby/2.0.0/gems/barby-0.6.3/lib/barby/barcode/qr_code.rb:95:in `rqrcode'
    from /home/orange/.gem/ruby/2.0.0/gems/barby-0.6.3/lib/barby/barcode/qr_code.rb:56:in `encoding'
    from /home/orange/.gem/ruby/2.0.0/gems/barby-0.6.3/lib/barby/outputter.rb:84:in `encoding'
    from /home/orange/.gem/ruby/2.0.0/gems/barby-0.6.3/lib/barby/outputter/png_outputter.rb:105:in `length'
    from /home/orange/.gem/ruby/2.0.0/gems/barby-0.6.3/lib/barby/outputter/png_outputter.rb:77:in `width'
    from /home/orange/.gem/ruby/2.0.0/gems/barby-0.6.3/lib/barby/outputter/png_outputter.rb:85:in `full_width'
    from /home/orange/.gem/ruby/2.0.0/gems/barby-0.6.3/lib/barby/outputter/png_outputter.rb:23:in `block in to_image'
    from /home/orange/.gem/ruby/2.0.0/gems/barby-0.6.3/lib/barby/outputter.rb:122:in `with_options'
    from /home/orange/.gem/ruby/2.0.0/gems/barby-0.6.3/lib/barby/outputter/png_outputter.rb:22:in `to_image'
    from /home/orange/.gem/ruby/2.0.0/gems/barby-0.6.3/lib/barby/outputter/png_outputter.rb:66:in `to_datastream'
    from /home/orange/.gem/ruby/2.0.0/gems/barby-0.6.3/lib/barby/outputter/png_outputter.rb:72:in `to_png'
    from /home/orange/.gem/ruby/2.0.0/gems/barby-0.6.3/lib/barby/barcode.rb:70:in `method_missing'
    from ./barby-test:12:in `block in <main>'
    from ./barby-test:11:in `open'
    from ./barby-test:11:in `<main>'

Patching lib/barby/barcode/qr_code.rb seems able to resolve this issue.

--- /home/orange/.gem/ruby/2.0.0/gems/barby-0.6.3/lib/barby/barcode/qr_code.rb.ori  2016-05-14 13:16:52.188170543 +1000
+++ /home/orange/.gem/ruby/2.0.0/gems/barby-0.6.3/lib/barby/barcode/qr_code.rb  2016-05-14 13:17:01.736170810 +1000
@@ -71,7 +71,7 @@
       return @size if @size

       level_index = LEVELS[level]
-      length = data.length
+      length = data.bytesize
       found_size = nil
       SIZES.each do |size,max_values|
         if max_values[level_index] >= length

This is probably because Japanese and Chinese character are not single-byte character

$ irb
irb(main):001:0> "おはようございます早安".length
=> 11
irb(main):002:0> "おはようございます早安".bytesize
=> 33

UPCs

Is there a way to output a standard format UPC barcode (you know, with the numbers overlaid on the barcode) with Barby? I've been looking at the rdocs and I haven't seen anything.

0.4.4 - `require': no such file to load -- rqrcode

Latest version reports:

/Users/karl/.rvm/gems/ruby-1.9.2-p180@lw/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in `require': no such file to load -- rqrcode (LoadError)
from /Users/karl/.rvm/gems/ruby-1.9.2-p180@lw/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in `block in require'
from /Users/karl/.rvm/gems/ruby-1.9.2-p180@lw/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in `block in load_dependency'
from /Users/karl/.rvm/gems/ruby-1.9.2-p180@lw/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:596:in `new_constants_in'
from /Users/karl/.rvm/gems/ruby-1.9.2-p180@lw/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in `load_dependency'
from /Users/karl/.rvm/gems/ruby-1.9.2-p180@lw/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in `require'
from /Users/karl/.rvm/gems/ruby-1.9.2-p180@lw/gems/barby-0.4.4/lib/barby/barcode/qr_code.rb:1:in `<top (required)>'

bundle does not install the rqrcode gem with barby.

Please include test/ into gem File

Hello,

could you please add the test directory into the next gem release?

So Debian can run tests after building for Gem as Debian file.

Thanks!

Ascii Code_128

Using code_128.rb generated:

RegexpError (/.../n has a non escaped non ASCII character in non ASCII-8BIT script):

I tested with => ruby-2.0.0-p576 [ x86_64 ]
and ruby-2.1.3 [ x86_64 ]. Same issue was closed in may.

EAN13 does not accept EAN13 codes (ArgumentError: data not valid)

I'm not able do generate any of my valid EAN13 codes (e.g. 4050486102473, 4050486086735, 5707471006665, 5998309302206)

require 'barby' 
require 'barby/barcode/ean_13' 
Barby::EAN13.new("4050486102473") 
ArgumentError: data not valid

Any ideas?
Thanks in advance!

issue with code_39 using chenky png

we got that error after updating this gem.
undefined method `to_png' for #<Barby::Code39:0x007ff702b3c940 @DaTa="85", @Extended=false>
please give me solution. i need this urgent tomorrow is my presentation of this project.

Switch type error

Hi, I'm trying to switch type from B to C when creating a barcode. I've tried you're example code but get an error:

Barby::Code128A.new("ABC123\306def\3074567")

ArgumentError:
invalid byte sequence in UTF-8

Could you please advise?

Thanks

#booleans should be a method of barcode but not an outputter

I need to use barby only to translate a code into a bitmap and write an outputter myself on my end without using the barby outputters infrustructure that just seems an unnecessary overhead to me.
But the #booleans is only available on formatter. That seems illogical because the bitmap doesn't depend on the outputter.

So I propose to move the method to the Barcode object itself.

Version Number

Hi
I'm not sure if this is really an issue or not, but when you rewrote the html parser, it seems that the version number was not incremented.
This way, when installing through bundler for example, I got a gem that claimed to be 0.5.0, just like the version in the repo here on github. but functionality differs. This makes for quite the confusing experience.
Otherwise, the gem works great and I'm really happy with the ease of use.

Kind regards
Philipp

Issues in scanning generated pdf417 barcode

Additional information for #47
I have added a sample program in Pdf417Barcode

Here is sample program I am using
code file

barcode_data = "Test Barcode"
postal_barcode = Barby::Pdf417.new(barcode_data)
image = Barby::PngOutputter.new(postal_barcode).to_png
File.open('barcode.png', 'w'){|f| f.write image }

you can check generated barcode

I am able to scan barcode generated by java library using
java Pdf417lib test_barcode.ps "Test Barcode"

OS : Mac OS X Yoesmite 10.10.3
Jruby version : jruby 1.7.20 (1.9.3p551) 2015-05-04 3086e6a on Java HotSpot(TM) 64-Bit Server VM 1.8.0_25-b17 +jit [darwin-x86_64]
Gems Used

for verifying I am using this site Online Barcode Decoder

and Barcode scanners by manatee Works on my android phone

Invalid barcode output with EAN13/UPC

I'm generating a barcode for an EAN13/UPC and it doesn't seem to be working properly:

barcode = Barby::EAN13.new('091037788863')
img#barcode src="data:image/svg+xml;base64,#{Base64.encode64(barcode.to_svg(margin: 0))}"

When I scan the resulting barcode, it's taking off the initial 0 and adding a trailing 0, resulting in 910377888630. What gives?

barby 0.5.1 fails HtmlOutputter tests

I'm seeing the following failure with ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]:

  1) Failure:
test_0006_should_build_the_expected_rows(HtmlOutputterTest) [/var/tmp/portage/dev-ruby/barby-0.5.1/work/ruby19/barby-0.5.1/test/outputter/html_outputter_test.rb:50]:
--- expected
+++ actual
@@ -1 +1 @@
-["<tr class=\"barby-row\"><td class=\"barby-cell on\"></td></tr><tr class=\"barby-row\"><td class=\"barby-cell off\"></td></tr>", "<tr class=\"barby-row\"><td class=\"barby-cell off\"></td></tr><tr class=\"barby-row\"><td class=\"barby-cell on\"></td></tr>"]
+["<tr class=\"barby-row\"><td class=\"barby-cell on\"></td><td class=\"barby-cell off\"></td></tr>", "<tr class=\"barby-row\"><td class=\"barby-cell off\"></td><td class=\"barby-cell on\"></td></tr>"]

number labels

Hi toretore, and barby contributors,

Would I be able to generate a barcode like the following attached image.
screen shot 2015-06-25 at 11 34 47 am

I see that ean13 with a 5 supplemental is possible. However I don't see a way to include the decimal digits. E.g. under the 13 and above the 5 in the image.

Thanks,
John

Pdf417 barcode is not getting scanned

I am generating a pdf417 barcode using below code. It is getting generated properly but i am not able to scan it. i am using prawn for generating pdf

barcode = Barby::Pdf417.new("Test Data")
barcode.annotate_pdf(@pdf, {:height => 25.mm, :xdim => 1.2, :x => 8.mm, :y => @pdf.cursor - 25.mm})

Support for GS1 SSCC barcodes

I can see that you support GS1-128 barcodes.

Would it be to specialized/"high level" to support Serial Shipping Container Code (SSCC-18)

Something like:

GS1_SSCC.new(data, application_identifier, extension_digit, company_prefix)

It would then automatically calculate the check digit and set the subset type to C

Example:

GS1_SSCC.new('000113256', '00', '3', '5712852')

would produce 00357128520001132567 - where 7 is the check digit calculated.

UPC Supplemental Breaks PNG Outputter

In the upc_supplemental symbology there is an error in the logic that determines whether it's 2 or 5 digit supplemental.

The current code is setting size to data.size. This results in either 14 or 17: 12 from EAN13/UPC-A plus the supplemental digits.

When determining which format it is, however, the current code checks to see whether size is 2 or 5.

This needs to be updated either to set size to data.size - 12, which returns the 2 or 5 it is currently looking for, or to check for size == 14 or size == 17, which is what it currently returns.

I changed the size method (lines 51-53) of /lib/barby/barcode/upc_supplemental.rb from

    def size
      data.size
    end

to

    def size
      (data.size - 12)
    end

This fixed the issue, and allowed the PNG outputter to function properly.

Consider Splitting Outputters into their own gems

Trying to use 'barby/outputter/png_outputter' threw a dependency error for chunky_png. Obviously you don't want to include every possible dependency into barby for each outputter, because they may not be used. Rather than requiring EVERY possible gem that the outputters require, why not split each outputter into its own gem with its own dependencies (barby being the first and foremost)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.