class Middleman::FastImage
def self.size(uri, options={})
If set to true causes an exception to be raised if the image size cannot be found for any reason.
[:raise_on_failure]
Overrides the default timeout of 2 seconds. Applies both to reading from and opening the http connection.
[:timeout]
=== Supported options
=> raises FastImage::SizeNotFound
FastImage.size("http://stephensykes.com/images/faulty.jpg", :raise_on_failure=>true)
=> raises FastImage::ImageFetchFailure
FastImage.size("http://stephensykes.com/favicon.ico", :raise_on_failure=>true, :timeout=>0.01)
=> raises FastImage::UnknownImageType
FastImage.size("http://stephensykes.com/favicon.ico", :raise_on_failure=>true)
=> raises FastImage::ImageFetchFailure
FastImage.size("http://pennysmalls.com/does_not_exist", :raise_on_failure=>true)
=> nil
FastImage.size("http://pennysmalls.com/does_not_exist")
=> [882, 470]
FastImage.size("test/fixtures/test.jpg")
=> [512, 512]
FastImage.size("http://www-ece.rice.edu/~wakin/images/lena512.bmp")
=> [500, 375]
FastImage.size("http://farm4.static.flickr.com/3023/3047236863_9dce98b836.jpg")
=> [16, 16]
FastImage.size("http://stephensykes.com/images/pngimage")
=> [266, 56]
FastImage.size("http://stephensykes.com/images/ss.com_x.gif")
require 'fastimage'
=== Example
FastImage knows about GIF, JPEG, BMP and PNG files.
:raise_on_failure => true in the options.
If you wish FastImage to raise if it cannot size the image for any reason, then pass
This can be changed by passing a :timeout => number_of_seconds in the options.
By default there is a timeout of 2 seconds for opening and reading from a remote server.
It will return nil if the image could not be fetched, or if the image type was not recognised.
Returns an array containing the width and height of the image.
def self.size(uri, options={}) new(uri, options).size end