Class | Barby::RmagickOutputter |
In: |
lib/barby/outputter/rmagick_outputter.rb
|
Parent: | Outputter |
height | [RW] | |
margin | [RW] | |
xdim | [RW] | |
ydim | [RW] |
Number of modules (xdims) on the x axis
# File lib/barby/outputter/rmagick_outputter.rb, line 91 91: def length 92: barcode.two_dimensional? ? encoding.first.length : encoding.length 93: end
# 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
# 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
# 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
# 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
# File lib/barby/outputter/rmagick_outputter.rb, line 18 18: def to_png(*a) 19: to_blob('png', *a) 20: end