class Tesseract::API::Image

Attributes

x[RW]
y[RW]

Public Class Methods

finalize(pointer) click to toggle source
# File lib/tesseract/api/image.rb, line 56
def self.finalize (pointer)
        C::Leptonica.pix_destroy(pointer)
end
new(image, x = 0, y = 0) click to toggle source
Calls superclass method
# File lib/tesseract/api/image.rb, line 28
def self.new (image, x = 0, y = 0)
        image = if image.is_a?(String) && (File.exists?(File.expand_path(image)) rescue nil)
                C::Leptonica.pix_read(File.expand_path(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)
        else
                image
        end

        raise ArgumentError, 'invalid image' if image.nil? || image.null?

        super(image, x, y)
end
new(pointer, x = 0, y = 0) click to toggle source
# File lib/tesseract/api/image.rb, line 50
def initialize (pointer, x = 0, y = 0)
        @internal = FFI::AutoPointer.new(pointer, self.class.method(:finalize))
        @x        = x
        @y        = y
end

Public Instance Methods

height() click to toggle source
# File lib/tesseract/api/image.rb, line 64
def height
        C::Leptonica.pix_get_height(to_ffi)
end
to_blob(format = :default) click to toggle source
# File lib/tesseract/api/image.rb, line 68
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))
        C.free(data.typecast(:pointer))

        result
end
to_ffi() click to toggle source
# File lib/tesseract/api/image.rb, line 79
def to_ffi
        @internal
end
width() click to toggle source
# File lib/tesseract/api/image.rb, line 60
def width
        C::Leptonica.pix_get_width(to_ffi)
end