Method: AsciiRenderer::Html#to_ascii_art

Defined in:
lib/asciiart/html.rb

#to_ascii_art(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/asciiart/html.rb', line 8

def to_ascii_art(options = {})
  width       = options[:width]
  scale       = (width.to_f / @img.columns)
  height      = ((@img.rows * scale) / 2).to_i
  
  img           = @img.resize(width, height)
  @color_img    = img.dup if options[:color]
  img           = img.quantize(image_chars.length, Magick::GRAYColorspace).normalize
  border = "+#{'-' * width}+<br/>"
  border = html_char(border)

  output = border.dup

  img.view(0, 0, width, height) do |view|
    height.times do |i|
      output << '|'
      width.times { |j| output << pixel_to_char(view, j: j, i: i, color: options[:color]) }
      output << "|<br/>"
    end
  end
  output + border
end