Skip to content

Instantly share code, notes, and snippets.

@greenbigfrog
Created May 30, 2021 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greenbigfrog/9bfafdac57a1dbc650507011da900732 to your computer and use it in GitHub Desktop.
Save greenbigfrog/9bfafdac57a1dbc650507011da900732 to your computer and use it in GitHub Desktop.
require "gobject"
require_gobject "Vips"
class Vips::Image
def self.new_from_file(path : String)
Vips::Image.new_from_file_rw(path)
end
# https://www.rubydoc.info/gems/ruby-vips/Vips/Image#cast-instance_method
def vips_cast(format)
LibVips.vips_cast(self, out casted, format)
Vips::Image.new(casted)
end
end
lib LibVips
alias Img = LibVips::Image
# https://libvips.github.io/libvips/API/current/libvips-conversion.html#vips-cast
fun vips_cast(input : Img*, output : Img**, band : Int32)
end
puts "Reading image"
img = Vips::Image.new_from_file("/home/frog/dhash-cr/test.jpg")
puts "Read img with width #{img.width} and height #{img.height}"
img.vips_cast(Vips::BandFormat::INT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment