Method: FastImage.type
- Defined in:
- lib/vendored-middleman-deps/fastimage.rb
.type(uri, options = {}) ⇒ Object
Returns an symbol indicating the image type fetched from a uri. It will return nil if the image could not be fetched, or if the image type was not recognised.
By default there is a timeout of 2 seconds for opening and reading from a remote server. This can be changed by passing a :timeout => number_of_seconds in the options.
If you wish FastImage to raise if it cannot find the type of the image for any reason, then pass :raise_on_failure => true in the options.
Example
require 'fastimage'
FastImage.type("http://stephensykes.com/images/ss.com_x.gif")
=> :gif
FastImage.type("http://stephensykes.com/images/pngimage")
=> :png
FastImage.type("http://farm4.static.flickr.com/3023/3047236863_9dce98b836.jpg")
=> :jpeg
FastImage.type("http://www-ece.rice.edu/~wakin/images/lena512.bmp")
=> :bmp
FastImage.type("test/fixtures/test.jpg")
=> :jpeg
FastImage.type("http://pennysmalls.com/does_not_exist")
=> nil
Supported options
[:timeout] Overrides the default timeout of 2 seconds. Applies both to reading from and opening the http connection. [:raise_on_failure] If set to true causes an exception to be raised if the image type cannot be found for any reason.
131 132 133 |
# File 'lib/vendored-middleman-deps/fastimage.rb', line 131 def self.type(uri, ={}) new(uri, .merge(:type_only=>true)).type end |