Class: BrotherEscp::Image

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

Overview

Main classe to manipulate images

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name:, converter: :single_density) ⇒ Image

Returns a new instance of Image.

Parameters:

  • file_name

    file name of the image to load

  • converter (Symbol) (defaults to: :single_density)

    set the image density, default to single_density, possible values are: :single_density, :high_density, :higher_density



14
15
16
17
18
# File 'lib/brother_escp/image.rb', line 14

def initialize(file_name:, converter: :single_density)
  load(file_name: file_name)

  load_converter(converter)
end

Instance Attribute Details

#converterObject (readonly)

Returns the value of attribute converter.



10
11
12
# File 'lib/brother_escp/image.rb', line 10

def converter
  @converter
end

#imageObject (readonly)

Returns the value of attribute image.



9
10
11
# File 'lib/brother_escp/image.rb', line 9

def image
  @image
end

Instance Method Details

#convertObject

Run the convert process. Create internally an array of lines

Returns:

  • self



32
33
34
35
# File 'lib/brother_escp/image.rb', line 32

def convert
  @lines = converter.convert(image: image)
  self
end

#inspectObject

Print some meta data to current image



21
22
23
24
25
26
27
28
# File 'lib/brother_escp/image.rb', line 21

def inspect
  puts "height    : #{@image.height}"
  puts "width     : #{@image.width}"
  puts "metadata  : #{@image.}"
  @lines&.each_with_index do |e, i|
    puts "#{i}: #{e.inspect}"
  end
end

#to_escpObject

Give the image data converted to the printer format



38
39
40
# File 'lib/brother_escp/image.rb', line 38

def to_escp
  @lines.map { |line| convert_line_to_escp(line) }.join
end