class Facy::ImageViewer::Image
Public Class Methods
new(path, options={})
click to toggle source
# File lib/facy/image_viewer.rb, line 27 def initialize(path, options={}) @image = Magick::ImageList.new(path) @fit_terminal = !!options[:fit_terminal] rescue Exception => e p e.message end
Public Instance Methods
ansi_analyze()
click to toggle source
# 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.message end
draw()
click to toggle source
# 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()
click to toggle source
# File lib/facy/image_viewer.rb, line 75 def get_term_size `stty size`.split(" ").map(&:to_i) end
puts_ansi()
click to toggle source
# 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()
click to toggle source
# 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