class FastImage
def initialize(uri, options={})
def initialize(uri, options={}) @property = options[:type_only] ? :type : :size @timeout = options[:timeout] || DefaultTimeout @uri = uri begin @parsed_uri = URI.parse(uri) rescue URI::InvalidURIError fetch_using_open_uri else if @parsed_uri.scheme == "http" || @parsed_uri.scheme == "https" fetch_using_http else fetch_using_open_uri end end raise SizeNotFound if options[:raise_on_failure] && @property == :size && !@size rescue Timeout::Error, SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET, ImageFetchFailure, Net::HTTPBadResponse, EOFError, Errno::ENOENT raise ImageFetchFailure if options[:raise_on_failure] rescue NoMethodError # 1.8.7p248 can raise this due to a net/http bug raise ImageFetchFailure if options[:raise_on_failure] rescue UnknownImageType raise UnknownImageType if options[:raise_on_failure] end