Class: Eikon::ImageProcessor
- Inherits:
-
Object
- Object
- Eikon::ImageProcessor
- Extended by:
- T::Sig
- Defined in:
- lib/eikon/image_processor.rb
Instance Attribute Summary collapse
-
#byte_array ⇒ Object
readonly
Returns the value of attribute byte_array.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #generate_byte_array ⇒ Object
-
#initialize(filename) ⇒ ImageProcessor
constructor
A new instance of ImageProcessor.
- #preprocess_image ⇒ Object
Constructor Details
#initialize(filename) ⇒ ImageProcessor
Returns a new instance of ImageProcessor.
18 19 20 21 22 |
# File 'lib/eikon/image_processor.rb', line 18 def initialize(filename) @filename = filename @image = T.let(Vips::Image.new_from_file(filename), Vips::Image) @byte_array = T.let("", String) end |
Instance Attribute Details
#byte_array ⇒ Object (readonly)
Returns the value of attribute byte_array.
12 13 14 |
# File 'lib/eikon/image_processor.rb', line 12 def byte_array @byte_array end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
15 16 17 |
# File 'lib/eikon/image_processor.rb', line 15 def filename @filename end |
Instance Method Details
#generate_byte_array ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/eikon/image_processor.rb', line 39 def generate_byte_array for y in 0..7 do for x in 0..7 do @byte_array += T.unsafe(@image).getpoint(x, y)[0] < T.unsafe(@image).getpoint((x + 1), y)[0] ? "1" : "0" end end nil end |
#preprocess_image ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/eikon/image_processor.rb', line 25 def preprocess_image # Black and white @image = T.unsafe(@image).colourspace "b-w" # For some reason thumbnail is only created via a buffer, so we save one quick image_buffer = @image.write_to_buffer ".tiff" # shrink image @image = T.unsafe(Vips::Image).thumbnail_buffer(image_buffer, 9, height: 8, size: :force) image_buffer = @image.write_to_buffer ".tiff" @image = Vips::Image.new_from_buffer(image_buffer, "") nil end |