lib/barby/outputter/png_outputter.rb
def to_image(opts={})
      with_options opts do
        canvas = ChunkyPNG::Image.new(full_width, full_height, ChunkyPNG::Color::WHITE)

        if barcode.two_dimensional?
          x, y = margin, margin
          booleans.each do |line|
            line.each do |bar|
              if bar
                x.upto(x+(xdim-1)) do |xx|
                  y.upto y+(ydim-1) do |yy|
                    canvas[xx,yy] = ChunkyPNG::Color::BLACK
                  end
                end
              end
              x += xdim
            end
            y += ydim
            x = margin
          end
        else
          x, y = margin, margin
          booleans.each do |bar|
            if bar
              x.upto(x+(xdim-1)) do |xx|
                y.upto y+(height-1) do |yy|
                  canvas[xx,yy] = ChunkyPNG::Color::BLACK
                end
              end
            end
            x += xdim
          end
        end

        canvas
      end
    end
def to_image(opts={})
      with_options opts do
        canvas = ChunkyPNG::Image.new(full_width, full_height, ChunkyPNG::Color::WHITE)

        if barcode.two_dimensional?
          x, y = margin, margin
          booleans.each do |line|
            line.each do |bar|
              if bar
                x.upto(x+(xdim-1)) do |xx|
                  y.upto y+(ydim-1) do |yy|
                    canvas[xx,yy] = ChunkyPNG::Color::BLACK
                  end
                end
              end
              x += xdim
            end
            y += ydim
            x = margin
          end
        else
          x, y = margin, margin
          booleans.each do |bar|
            if bar
              x.upto(x+(xdim-1)) do |xx|
                y.upto y+(height-1) do |yy|
                  canvas[xx,yy] = ChunkyPNG::Color::BLACK
                end
              end
            end
            x += xdim
          end
        end

        canvas
      end
    end
Creates a PNG::Canvas object and renders the barcode on it