libvips / ruby-vips

Ruby extension for the libvips image processing library.
MIT License
832 stars 61 forks source link

error when attempting to read EXIF orientation #122

Closed tomasc closed 7 years ago

tomasc commented 7 years ago

@jcupitt perhaps something to do with the ffi rewrite?

img = Vips::Image.new_from_file('FOO.JPG')
img.get("exif-ifd0-Orientation")
Vips::Error: unimplemented gtype for get: 140194323501504
    from /.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/ruby-vips-2.0.0/lib/vips/gvalue.rb:211:in `get'
    from /.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/ruby-vips-2.0.0/lib/vips/image.rb:492:in `get'
tomasc commented 7 years ago

PS the autorotate flag works correctly

kleisauke commented 7 years ago

Try this:

require 'vips'

img = Vips::Image.new_from_file('FOO.JPG')

# Check if it has a orientation tag
if img.get_typeof("orientation") != 0
    # Output the int from 1 - 8 using the standard exif/tiff meanings
    puts img.get("orientation")
else
    puts "No orientation tag"
end

Not long ago I had the same problem (with php), see: https://github.com/jcupitt/php-vips/issues/13#issuecomment-252412013.

jcupitt commented 7 years ago

Kleis is right, the orientation tag is the new official way to do this.

But using the ifd should have worked too, it sounds like a case might be missing from the thing to read values. I'll have a look.

jcupitt commented 7 years ago

Yes, the vips reference counted string gtype was missing. I now see:

$ irb
irb(main):001:0> require 'vips'
=> true
irb(main):002:0> x = Vips::Image.new_from_file "/home/john/pics/k2.jpg"
=> #<Image 1450x2048 uchar, 3 bands, srgb>
irb(main):003:0> x.get "exif-ifd0-Orientation"
=> "1 (Top-left, Short, 1 components, 2 bytes)"

I'll add a test and push a new version. Thanks for reporting this dumbness!

jcupitt commented 7 years ago

v2.0.1 push to rubygems

tomasc commented 7 years ago

Wonderful, thanks! I will give it a test right now.

tomasc commented 7 years ago

Just to confirm, all works fine now. Thanks again.