lib/barby/outputter/rmagick_outputter.rb in barby-0.6.2 vs lib/barby/outputter/rmagick_outputter.rb in barby-0.6.3

- old
+ new

@@ -1,21 +1,26 @@ require 'barby/outputter' -require 'RMagick' +require 'rmagick' module Barby #Renders images from barcodes using RMagick # #Registers the to_png, to_gif, to_jpg and to_image methods class RmagickOutputter < Outputter - + register :to_png, :to_gif, :to_jpg, :to_image - attr_accessor :height, :xdim, :ydim, :margin + attr_writer :height, :xdim, :ydim, :margin + def initialize(*) + super + @height, @xdim, @ydim, @margin = nil + end + #Returns a string containing a PNG image def to_png(*a) to_blob('png', *a) end @@ -26,18 +31,18 @@ #Returns a string containing a JPEG image def to_jpg(*a) to_blob('jpg', *a) end - + def to_blob(format, *a) img = to_image(*a) blob = img.to_blob{|i| i.format = format } - + #Release the memory used by RMagick explicitly. Ruby's GC #isn't aware of it and can't clean it up automatically img.destroy! if img.respond_to?(:destroy!) - + blob end #Returns an instance of Magick::Image def to_image(opts={})