Class: TianjiQRCodePNG::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/tianji_qrcode_png/image.rb

Constant Summary collapse

BLACK =
::ChunkyPNG::Color::BLACK
WHITE =
::ChunkyPNG::Color::WHITE
TRANSPARENT =
::ChunkyPNG::Color::TRANSPARENT

Instance Method Summary collapse

Constructor Details

#initialize(qr_code) ⇒ Image



7
8
9
# File 'lib/tianji_qrcode_png/image.rb', line 7

def initialize(qr_code)
  @sequence = Sequence.new(qr_code)
end

Instance Method Details

#render(bg_color, color, border) ⇒ Object

重写render方法,加入二维码颜色和边框参数



12
13
14
15
16
17
18
19
# File 'lib/tianji_qrcode_png/image.rb', line 12

def render(bg_color, color, border)
  @sequence.border = border.to_i
  png = blank_img(bg_color)
  @sequence.dark_squares_only do |x, y|
    png[y + @sequence.border_width(), x + @sequence.border_width()] = color
  end
  return png
end