Skip to content

Instantly share code, notes, and snippets.

@oleriesenberg
Created September 18, 2011 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oleriesenberg/1225301 to your computer and use it in GitHub Desktop.
Save oleriesenberg/1225301 to your computer and use it in GitHub Desktop.
def determine_mime_type(io)
blob = io.read(10)
return 'image/gif' if blob.match(/^GIF8/)
return 'image/png' if blob.match(/^\x89PNG/)
return 'image/jpeg' if blob.match(/^\xff\xd8\xff\xe0\x00\x10JFIF/)
return 'image/jpeg' if blob.match(/^\xff\xd8\xff\xe1(.*){2}Exif/)
'unknown'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment