chriseppstein/compass — pull request #905 by johnbintz (2012-05-26 01:17:52+00:00)
Title: Retrieve image properties from filesystem-like objects

I want to use a MongoDB `GridFileSystem` as a source of images for Compass, and need to be able to analyze the images in the filesystem for dimension information. This patch provides the configuration parameter `images_file_source`, which accepts a `Proc` or `lambda` that accepts the path of the file to be analyzed and returns an `IO`-like object that can be used in the `ImageProperties` analysis. With this setup, using a `GridFileSystem` source for image data can be done like this:

``` ruby
require 'forwardable'

class CompassGridIO < Delegator
extend Forwardable

def initialize(io)
@io = io
end

def_delegators :io, :read, :close

def readbyte
@io.getc.bytes.first
end
end

Compass.configuration.images_file_source = lambda { |file|
file = file.gsub(%r{^[\./]+}, '') # got to rip off any leading path characters

CompassGridIO.new(grid_file_system.open(file, 'r'))
}
```

Having a file in `grid_file_system` at, say, `file.jpg`, will be accessed correctly when using any of the image-size methods in Sass:

``` scss
#logo {
width: image-width('file.jpg');
height: image-height('file.jpg');
background: image-url('file.jpg');
}
```