Class: CliPix::Image
- Inherits:
-
Object
- Object
- CliPix::Image
- Defined in:
- lib/cli_pix/image.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ autoscale: true, size: nil, flop: false, flip: false, mode: :color, preprocess: false }
Instance Attribute Summary collapse
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .from_blob ⇒ Object
- .open(url, options = {}) ⇒ Object (also: from_url, from_file)
- .read(blob, options = {}) ⇒ Object
Instance Method Summary collapse
- #animate(framerate = 0.2) ⇒ Object
- #display ⇒ Object
-
#initialize(image, options = {}) ⇒ Image
constructor
A new instance of Image.
-
#read ⇒ Object
yields each text frame to the block.
Constructor Details
#initialize(image, options = {}) ⇒ Image
Returns a new instance of Image.
36 37 38 39 |
# File 'lib/cli_pix/image.rb', line 36 def initialize(image, = {}) @image = image = DEFAULT_OPTIONS.merge end |
Instance Attribute Details
#image ⇒ Object (readonly)
Returns the value of attribute image.
34 35 36 |
# File 'lib/cli_pix/image.rb', line 34 def image @image end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
34 35 36 |
# File 'lib/cli_pix/image.rb', line 34 def end |
Class Method Details
.from_blob ⇒ Object
23 24 25 26 |
# File 'lib/cli_pix/image.rb', line 23 def read(blob, = {}) image = MiniMagick::Image.read(blob) self.new(image, ) end |
.open(url, options = {}) ⇒ Object Also known as: from_url, from_file
25 26 27 28 |
# File 'lib/cli_pix/image.rb', line 25 def open(url, = {}) image = MiniMagick::Image.open(url) self.new(image, ) end |
.read(blob, options = {}) ⇒ Object
19 20 21 22 |
# File 'lib/cli_pix/image.rb', line 19 def read(blob, = {}) image = MiniMagick::Image.read(blob) self.new(image, ) end |
Instance Method Details
#animate(framerate = 0.2) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/cli_pix/image.rb', line 49 def animate(framerate = 0.2) self.read do |text| # clear terminal clear_screen! puts text # wait sleep framerate end end |
#display ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/cli_pix/image.rb', line 41 def display self.read do |text| # clear terminal clear_screen! puts text end end |
#read ⇒ Object
yields each text frame to the block
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/cli_pix/image.rb', line 60 def read process_image! if [:preprocess] # | / - \ spinner = "|/-\\" text_frames = image.frames.map.with_index do |frame, index| print "Loading frame #{index + 1}/#{image.frames.length}... #{spinner[index % 4]} \r" if [:mode] == :color convert_to_color(frame.get_pixels) else convert_to_ascii(frame.get_pixels) end end text_frames.each do |text_frame| yield text_frame end else image.frames.each do |frame| if [:mode] == :color yield convert_to_color(frame.get_pixels) else yield convert_to_ascii(frame.get_pixels) end end end end |