Sha256: ae4e9a04a3540c8bf01035a81f49941bd3c598f06964e3fe97a1469e1bdf2365

Contents?: true

Size: 1.03 KB

Versions: 23

Compression:

Stored size: 1.03 KB

Contents

def image_properties(image)
  details = `identify #{image.path}`
  raise "couldn't identify #{image.path} in image_properties" if details.empty?
  # example of details string:
  # myimage.png PNG 200x100 200x100+0+0 8-bit DirectClass 31.2kb
  filename, format, geometry, geometry_2, depth, image_class, size = details.split(' ')
  width, height = geometry.split('x')
  {
    :filename => filename,
    :format => format.downcase,
    :width => width.to_i,
    :height => height.to_i,
    :depth => depth,
    :image_class => image_class,
    :size => size.to_i
  }
end

[:width, :height, :format, :size].each do |property|

  RSpec::Matchers.define "have_#{property}" do |value|
    match do |actual|
      value.should === image_properties(actual)[property]
    end
    failure_message_for_should do |actual|
      "expected image to have #{property} #{value.inspect}, but it had #{image_properties(actual)[property].inspect}"
    end
  end

end

RSpec::Matchers.define :equal_image do |other|
  match do |given|
    given.data == other.data
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
dragonfly-1.4.0 spec/support/image_matchers.rb
dragonfly-1.3.0 spec/support/image_matchers.rb
dragonfly-1.2.1 spec/support/image_matchers.rb
dragonfly-1.2.0 spec/support/image_matchers.rb
dragonfly-1.1.5 spec/support/image_matchers.rb
dragonfly-1.1.4 spec/support/image_matchers.rb
dragonfly-1.1.3 spec/support/image_matchers.rb
dragonfly-1.1.2 spec/support/image_matchers.rb
dragonfly-1.1.1 spec/support/image_matchers.rb
dragonfly-1.1.0 spec/support/image_matchers.rb
dragonfly-1.0.12 spec/support/image_matchers.rb
dragonfly-1.0.11 spec/support/image_matchers.rb
dragonfly-1.0.10 spec/support/image_matchers.rb
dragonfly-1.0.9 spec/support/image_matchers.rb
dragonfly-1.0.8 spec/support/image_matchers.rb
dragonfly-1.0.7 spec/support/image_matchers.rb
dragonfly-1.0.6 spec/support/image_matchers.rb
dragonfly-1.0.5 spec/support/image_matchers.rb
dragonfly-1.0.4 spec/support/image_matchers.rb
dragonfly-1.0.3 spec/support/image_matchers.rb