Class Barby::RmagickOutputter
In: lib/barby/outputter/rmagick_outputter.rb
Parent: Outputter
EAN13 Bookland EAN8 Barcode1D Code128 Code25 Code93 Code39 Barcode Barcode2D QrCode Pdf417 Code128A Code128B Code128C GS1128 Outputter CairoOutputter PngOutputter ASCIIOutputter PDFWriterOutputter RmagickOutputter PrawnOutputter SvgOutputter Code25IATA Code25Interleaved lib/barby/barcode/gs1_128.rb lib/barby/outputter/png_outputter.rb lib/barby/outputter/svg_outputter.rb lib/barby/outputter/rmagick_outputter.rb lib/barby/barcode.rb lib/barby/outputter/ascii_outputter.rb lib/barby/outputter.rb lib/barby/barcode/code_128.rb lib/barby/barcode/code_39.rb lib/barby/outputter/pdfwriter_outputter.rb lib/barby/barcode/code_93.rb lib/barby/outputter/prawn_outputter.rb lib/barby/barcode/pdf_417.rb lib/barby/barcode/ean_8.rb lib/barby/barcode/code_25_iata.rb lib/barby/outputter/cairo_outputter.rb lib/barby/barcode/ean_13.rb lib/barby/barcode/code_25.rb lib/barby/barcode/code_25_interleaved.rb lib/barby/barcode/qr_code.rb lib/barby/barcode/bookland.rb VERSION Barby dot/m_22_0.png

Renders images from barcodes using RMagick

Registers the to_png, to_gif, to_jpg and to_image methods

Methods

full_height   full_width   height   length   margin   to_blob   to_gif   to_image   to_jpg   to_png   width   xdim   ydim  

Attributes

height  [RW] 
margin  [RW] 
xdim  [RW] 
ydim  [RW] 

Public Instance methods

The height of the image. This is the height of the barcode + the top and bottom margin

[Source]

     # File lib/barby/outputter/rmagick_outputter.rb, line 118
118:     def full_height
119:       height + (margin * 2)
120:     end

The full width of the image. This is the width of the barcode + the left and right margin

[Source]

     # File lib/barby/outputter/rmagick_outputter.rb, line 112
112:     def full_width
113:       width + (margin * 2)
114:     end

The height of the barcode in px For 2D barcodes this is the number of "lines" * ydim

[Source]

    # File lib/barby/outputter/rmagick_outputter.rb, line 81
81:     def height
82:       barcode.two_dimensional? ? (ydim * encoding.length) : (@height || 100)
83:     end

Number of modules (xdims) on the x axis

[Source]

    # File lib/barby/outputter/rmagick_outputter.rb, line 91
91:     def length
92:       barcode.two_dimensional? ? encoding.first.length : encoding.length
93:     end

The margin of each edge surrounding the barcode in pixels

[Source]

     # File lib/barby/outputter/rmagick_outputter.rb, line 106
106:     def margin
107:       @margin || 10
108:     end

[Source]

    # File lib/barby/outputter/rmagick_outputter.rb, line 32
32:     def to_blob(format, *a)
33:       img = to_image(*a)
34:       blob = img.to_blob{|i| i.format = format }
35:       
36:       #Release the memory used by RMagick explicitly. Ruby's GC
37:       #isn't aware of it and can't clean it up automatically
38:       img.destroy! if img.respond_to?(:destroy!)
39:       
40:       blob
41:     end

Returns a string containint a GIF image

[Source]

    # File lib/barby/outputter/rmagick_outputter.rb, line 23
23:     def to_gif(*a)
24:       to_blob('gif', *a)
25:     end

Returns an instance of Magick::Image

[Source]

    # File lib/barby/outputter/rmagick_outputter.rb, line 44
44:     def to_image(opts={})
45:       with_options opts do
46:         canvas = Magick::Image.new(full_width, full_height)
47:         bars = Magick::Draw.new
48: 
49:         x = margin
50:         y = margin
51: 
52:         if barcode.two_dimensional?
53:           encoding.each do |line|
54:             line.split(//).map{|c| c == '1' }.each do |bar|
55:               if bar
56:                 bars.rectangle(x, y, x+(xdim-1), y+(ydim-1))
57:               end
58:               x += xdim
59:             end
60:             x = margin
61:             y += ydim
62:           end
63:         else
64:           booleans.each do |bar|
65:             if bar
66:               bars.rectangle(x, y, x+(xdim-1), y+(height-1))
67:             end
68:             x += xdim
69:           end
70:         end
71: 
72:         bars.draw(canvas)
73: 
74:         canvas
75:       end
76:     end

Returns a string containing a JPEG image

[Source]

    # File lib/barby/outputter/rmagick_outputter.rb, line 28
28:     def to_jpg(*a)
29:       to_blob('jpg', *a)
30:     end

Returns a string containing a PNG image

[Source]

    # File lib/barby/outputter/rmagick_outputter.rb, line 18
18:     def to_png(*a)
19:       to_blob('png', *a)
20:     end

The width of the barcode in px

[Source]

    # File lib/barby/outputter/rmagick_outputter.rb, line 86
86:     def width
87:       length * xdim
88:     end

X dimension. 1X == 1px

[Source]

    # File lib/barby/outputter/rmagick_outputter.rb, line 96
96:     def xdim
97:       @xdim || 1
98:     end

Y dimension. Only for 2D codes

[Source]

     # File lib/barby/outputter/rmagick_outputter.rb, line 101
101:     def ydim
102:       @ydim || xdim
103:     end

[Validate]