Class: Facy::ImageViewer::Image
- Inherits:
-
Object
- Object
- Facy::ImageViewer::Image
- Defined in:
- lib/facy/image_viewer.rb
Instance Method Summary collapse
- #ansi_analyze ⇒ Object
- #draw ⇒ Object
- #get_term_size ⇒ Object
-
#initialize(path, options = {}) ⇒ Image
constructor
A new instance of Image.
- #puts_ansi ⇒ Object
- #rgb_analyze ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ Image
Returns a new instance of Image.
27 28 29 30 31 32 |
# File 'lib/facy/image_viewer.rb', line 27 def initialize(path, ={}) @image = Magick::ImageList.new(path) @fit_terminal = !![:fit_terminal] rescue Exception => e p e. end |
Instance Method Details
#ansi_analyze ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/facy/image_viewer.rb', line 57 def ansi_analyze raise "use rgb_analyze before ansi_analyze" unless @rgb ret = [] @rgb.map! do |row| ret << row.map{|pixcel| AnsiRGB.wrap_with_code(@double ? " " : " ", pixcel) }.join end @ansi = ret.join("\n") rescue Exception => e error e. end |
#draw ⇒ Object
34 35 36 37 38 39 |
# File 'lib/facy/image_viewer.rb', line 34 def draw convert_to_fit_terminal_size if @fit_terminal rgb_analyze ansi_analyze puts_ansi end |
#get_term_size ⇒ Object
75 76 77 |
# File 'lib/facy/image_viewer.rb', line 75 def get_term_size `stty size`.split(" ").map(&:to_i) end |
#puts_ansi ⇒ Object
70 71 72 73 |
# File 'lib/facy/image_viewer.rb', line 70 def puts_ansi raise "use ansi_analyze before to_ansi" unless @ansi puts @ansi end |
#rgb_analyze ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/facy/image_viewer.rb', line 41 def rgb_analyze @rgb = [] cols = @image.columns rows = @image.rows rows.times do |y| cols.times do |x| @rgb[y] ||= [] pixcel = @image.pixel_color(x, y) r = pixcel.red / 256 g = pixcel.green / 256 b = pixcel.blue / 256 @rgb[y] << [r, g, b] end end end |