exif icon indicating copy to clipboard operation
exif copied to clipboard

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

Open dirceu-jr opened this issue 7 years ago • 3 comments

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

dirceu-jr avatar Feb 08 '18 18:02 dirceu-jr

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

tonytonyjan avatar Mar 09 '18 18:03 tonytonyjan

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".

谢谢

dirceu-jr avatar Mar 09 '18 20:03 dirceu-jr

@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

chrt00 avatar Dec 16 '18 00:12 chrt00