remvee / exifr

EXIF Reader
https://remvee.github.io/exifr/
MIT License
489 stars 66 forks source link

orientation comes back as object when calling .to_hash method #3

Closed markbate closed 14 years ago

markbate commented 14 years ago

The .to_hash method flattens jpeg metadata + EXIF metadata into a 1D Hash of metadata. As far as I can tell this works for all fields except the orientation, which comes back as an object of class "EXIFR::TIFF:Orientation" (should be an int of value 1-8). Note: I'm using the exifr gem version 0.10.9

Eg.

EXIF DATA for images/other/sony-d700.jpg x_resolution : 72 metering_mode : 2 color_space : 1 aperture_value : 5/2 resolution_unit : 2 y_resolution : 72 image_description : date_time_original : Tue Dec 01 14:22:36 +1100 1998 pixel_x_dimension : 1344 ycb_cr_positioning : 1 exposure_program : 3 make : SONY date_time_digitized : Tue Dec 01 14:22:36 +1100 1998 flash : 0 pixel_y_dimension : 1024 exposure_bias_value : 0 height : 512 model : DSC-D700 iso_speed_ratings : 200 bits : 8 date_time : Tue Dec 01 14:22:36 +1100 1998 compressed_bits_per_pixel : 6 comment : orientation : #EXIFR::TIFF::Orientation:0x1015c3b70 shutter_speed_value : 5 width : 672

It appear it's just a case of casting the value to an int, so I've managed to get around it with a couple of lines:

if( ret_hash[:orientation].class == EXIFR::TIFF::Orientation )
    ret_hash[:orientation] = ret_hash[:orientation].to_i
end

no biggie, it'd just be nice if I didn't have to do this. otherwise, it's great & doing exactly what I need it to do. thanks, mark

remvee commented 14 years ago

The to_hash method does flatten all information into a simple hash but doesn't clobber the actual values. Flattening EXIF::TIFF::Orientation to a number doesn't really make sence to me. The orientation instance is a feature, like date_time becoming a Time object instead of the original string which is stored in the image.

I must admit the inspect of the result hash is ugly. I'll open another issue for that.