tonytonyjan / exif

The fastest Ruby EXIF reader.
MIT License
150 stars 20 forks source link

"\xCD" from ASCII-8BIT to UTF-8 #20

Open dirceu-jr opened 6 years ago

dirceu-jr commented 6 years ago

While trying to use exif in a Rails app (utf-8 by default).

tonytonyjan commented 6 years ago

Can you give me some examples or sample images so that I can reproduce the same issue? Thanks!

dirceu-jr commented 6 years ago

Hi. I tried again today. I could get it to print exif data into Terminal. But when I try to render it in the Rails app, like:

file_io = IO.read(filename)
img_data = Exif::Data.new(file_io)
exif = img_data[:exif]    
render json: exif

Rails throws:

Encoding::UndefinedConversionError ("\xA5" from ASCII-8BIT to UTF-8):

I'm using "exifr" until I figure out how to use "exif".

谢谢

chrt00 commented 5 years ago

@dirceup you should just force the string to convert to UTF-8.

str.encode(Encoding.find('UTF-8'), {invalid: :replace, undef: :replace, replace: ''})

https://stackoverflow.com/questions/12947910/force-strings-to-utf-8-from-any-encoding