Is it possible to check that a picture that I downloaded is readable, if a picture viewer is going to tell me it cannot open it for some reason.
Example:
"invalid byte sequence in conversion input" when mousepad is used because Ephoto could not open it on Linux ) in Ruby
I download my picture with OpenURI and then output it in a file. Is there a function/gem that would allow to do that?
pic_buffer = open(my_link, "User-Agent" => "Ruby/#{RUBY_VERSION}")
if function_to_check_if_the_picture_is_readable(pic_buffer) == false
abort("file is unreadable")
end
if pic_buffer != nil
File.open(name_buffer + ".jpg", 'wb') do |pic|
pic << pic_buffer.read
end
end
I am downloading JPEG pictures only.
The only real way to tell if a JPEG image (as true with most compressed image formats) is to decompress it. You can do some sanity checks on the stream structure that will show some streams that cannot open. However, errors in the compressed data can only be found by expanding them. There is no CRC checking in JPEG as there is in PNG.