Class: Convert2Ascii::Image2Ascii

Inherits:
Object
  • Object
show all
Defined in:
lib/convert2ascii/image2ascii.rb

Defined Under Namespace

Modules: COLOR_ENUM, STYLE_ENUM

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Image2Ascii

Returns a new instance of Image2Ascii.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/convert2ascii/image2ascii.rb', line 27

def initialize(**args)
  @uri = args[:uri]
  @width = args[:width] || IO.console.winsize[1]
  @style = args[:style] || STYLE_ENUM::Color # "color": color ansi , "text": plain text
  @color = args[:color] || COLOR_ENUM::Full # full
  @color_block = args[:color_block] || false

  check_quantum_convert_factor
  # divides quantum depth color space into usable rgb values
  @quantum_convert_factor = Magick::MAGICKCORE_QUANTUM_DEPTH == 16 ? 257 : 1

  @chars = ".'`^\",:;Il!i><~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$"
  @ascii_string = ""
end

Instance Attribute Details

#ascii_stringObject (readonly)

Returns the value of attribute ascii_string.



24
25
26
# File 'lib/convert2ascii/image2ascii.rb', line 24

def ascii_string
  @ascii_string
end

#charsObject

Returns the value of attribute chars.



25
26
27
# File 'lib/convert2ascii/image2ascii.rb', line 25

def chars
  @chars
end

#widthObject (readonly)

Returns the value of attribute width.



24
25
26
# File 'lib/convert2ascii/image2ascii.rb', line 24

def width
  @width
end

Instance Method Details

#check_quantum_convert_factorObject



42
43
44
45
46
47
# File 'lib/convert2ascii/image2ascii.rb', line 42

def check_quantum_convert_factor
  # quantum conversion factor for dealing with quantum depth color values
  if Magick::MAGICKCORE_QUANTUM_DEPTH > 16
    raise Image2AsciiError, "[Error] ImageMagick quantum depth is set to #{Magick::MAGICKCORE_QUANTUM_DEPTH}. It needs to be 16 or less"
  end
end

#generate(**args) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/convert2ascii/image2ascii.rb', line 49

def generate(**args)
  @width = args[:width] || @width
  @style = args[:style] || @style # "color": color ansi , "text": plain text
  @color = args[:color] || @color # full
  @color_block = args[:color_block] || @color_block

  generate_string

  self
end

#tty_printObject



60
61
62
# File 'lib/convert2ascii/image2ascii.rb', line 60

def tty_print
  print @ascii_string
end