def open_file filename
      image_file = open(filename)
      return image_file unless image_file.is_a?(StringIO)

      base_name = File.basename(filename)
      temp_file = Tempfile.new(base_name)

      temp_file.binmode
      temp_file.write(image_file.read)
      temp_file.close

      open(temp_file.path)
    end
def open_file filename
      image_file = open(filename)
      return image_file unless image_file.is_a?(StringIO)

      base_name = File.basename(filename)
      temp_file = Tempfile.new(base_name)

      temp_file.binmode
      temp_file.write(image_file.read)
      temp_file.close

      open(temp_file.path)
    end
The Twitter gem is particular about the type of IO object it
   recieves when tweeting an image. If an image is < 10kb, Ruby opens it as a
   StringIO object. Which is not supported by the Twitter gem/api.

   This method ensures we always have a valid IO object for Twitter.