barby outputter

496 views
Skip to first unread message

Bob Mattax

unread,
Oct 21, 2009, 4:15:27 PM10/21/09
to Barby
Hi. Congrats on making a simple utility. The raw Barby stuff, that
is. :)

The part I'm struggling with is the outputter side of the equation.

It seems that the to_image function expect to create an image of a
particular size. I can't seem to get it to make the image size I
want, directly out of the output function.

Any suggestions?

Bob

Tore Darell

unread,
Oct 21, 2009, 4:33:50 PM10/21/09
to Barby
Hi Bob,

Which outputter are you using? The final size of an image will depend
on what's in the barcode and what you set various options to. As an
example, using the PngOutputter you can set the margin, height and
xdim:

barcode.to_png(:xdim => 3, :height => 200, :margin => 20)

This is for a 1D barcode; 2D barcodes can also set a ydim. You can't
set the width (or the height in the case of 2D barcodes) directly
because to be able to fit the data the image has to be a certain size.
If you need to predict the final size of an image, you can create an
instance and read the width and height attributes:

outputter = barcode.outputter_for(:to_png)
outputter.full_width #Returns width in pixels
outputter.full_height#"full" means include margins

This is for the PngOutputter, others have similar methods and options.

Tore

Bob Mattax

unread,
Oct 21, 2009, 4:36:08 PM10/21/09
to ruby-...@googlegroups.com
Great. I think that is enough to help.

I had tried using the rmagick outputter and the png outputter, but
couldn't find a concrete example of modifying any of the properties.

Thanks,
bob

Umberto Brighetti

unread,
May 12, 2013, 1:12:04 AM5/12/13
to ruby-...@googlegroups.com
Hi Tore,
I'm using rmagick

controller

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

    @barcode = Barby::Code128B.new(@guest.cf)
    @outputter = Barby::RmagickOutputter.new(@barcode)


view

<%= @outputter %>

but the result is

#<Magick::Image:0x007fa4b10507a0>

Can you help me!
Regards
Reply all
Reply to author
Forward
0 new messages