Class: Tesseract::API::Image
- Inherits:
-
Object
- Object
- Tesseract::API::Image
- Defined in:
- lib/tesseract/api/image.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
- #height ⇒ Object
-
#initialize(pointer, x = 0, y = 0) ⇒ Image
constructor
A new instance of Image.
- #to_blob(format = :default) ⇒ Object
- #to_ffi ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(pointer, x = 0, y = 0) ⇒ Image
Returns a new instance of Image.
48 49 50 51 52 |
# File 'lib/tesseract/api/image.rb', line 48 def initialize (pointer, x = 0, y = 0) @internal = FFI::AutoPointer.new(pointer, self.class.method(:finalize)) @x = x @y = y end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
46 47 48 |
# File 'lib/tesseract/api/image.rb', line 46 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
46 47 48 |
# File 'lib/tesseract/api/image.rb', line 46 def y @y end |
Class Method Details
.finalize(pointer) ⇒ Object
54 55 56 |
# File 'lib/tesseract/api/image.rb', line 54 def self.finalize (pointer) C::Leptonica.pix_destroy(pointer) end |
.new(image) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tesseract/api/image.rb', line 28 def self.new (image) image = if image.is_a?(String) && (File.exists?(File.(image)) rescue nil) C::Leptonica.pix_read(File.(image)) elsif image.is_a?(String) C::Leptonica.pix_read_mem(image, image.bytesize) elsif image.is_a?(IO) C::Leptonica.pix_read_stream(image.to_i) elsif image.respond_to? :to_blob image = image.to_blob C::Leptonica.pix_read_mem(image, image.bytesize) end raise ArgumentError, 'invalid image' if image.nil? || image.null? super(image) end |
Instance Method Details
#height ⇒ Object
62 63 64 |
# File 'lib/tesseract/api/image.rb', line 62 def height C::Leptonica.pix_get_height(to_ffi) end |
#to_blob(format = :default) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/tesseract/api/image.rb', line 66 def to_blob (format = :default) data = FFI::MemoryPointer.new(:pointer) size = FFI::MemoryPointer.new(:size_t) C::Leptonica.pix_write_mem(to_ffi, data, size, C.for_enum(format)) result = data.typecast(:pointer).read_string(size.typecast(:size_t)) data.typecast(:pointer).free result end |
#to_ffi ⇒ Object
79 80 81 |
# File 'lib/tesseract/api/image.rb', line 79 def to_ffi @internal end |