Class: CMagick::LoadImage

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

Overview

cmagick = CMagick::LoadImage.new(‘/path/to/img.jpg’) cmagick.show

if img is big size

cmagick.resize(0.1).show

Instance Method Summary collapse

Constructor Details

#initialize(img_path = '', image: Magick::ImageList.new(img_path), converter: RGBToANSI, bg: "\x1b[48;5;") ⇒ LoadImage

Returns a new instance of LoadImage.



17
18
19
20
21
22
23
24
25
# File 'lib/cmagick.rb', line 17

def initialize(img_path = '',
               image: Magick::ImageList.new(img_path),
               converter: RGBToANSI,
               bg: "\x1b[48;5;")
  @img_path  = img_path
  @image     = image
  @converter = converter
  @bg        = bg
end

Instance Method Details

#ansi_colorsObject



50
51
52
53
54
# File 'lib/cmagick.rb', line 50

def ansi_colors
  pixels_2d.map do |pixels|
    pixels.map { |r, g, b| @converter.call(r, g, b) }
  end
end

#resize(scale = 1.0) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cmagick.rb', line 37

def resize(scale = 1.0)
  if @img_path == ''
    return LoadImage.new(image: @image.resize(scale),
                         converter: @converter,
                         bg: @bg)
  end

  LoadImage.new(@img_path,
                image: @image.resize(scale),
                converter: @converter,
                bg: @bg)
end

#showObject



27
28
29
30
31
32
33
34
35
# File 'lib/cmagick.rb', line 27

def show
  ansi_colors.each do |ansi_color|
    ansi_color.each do |code|
      print "#{color(code)}  "
    end
    puts
  end
  puts
end