diff --git a/lib/compass/sass_extensions/functions/image_size.rb b/lib/compass/sass_extensions/functions/image_size.rb index 453010bc..864b8cdc 100644 --- a/lib/compass/sass_extensions/functions/image_size.rb +++ b/lib/compass/sass_extensions/functions/image_size.rb @@ -1,10 +1,12 @@ module Compass::SassExtensions::Functions::ImageSize + # Returns the width of the image relative to the images directory def image_width(image_file) image_path = real_path(image_file) width = ImageProperties.new(image_path).size.first Sass::Script::Number.new(width,["px"]) end + # Returns the height of the image relative to the images directory def image_height(image_file) image_path = real_path(image_file) height = ImageProperties.new(image_path).size.last @@ -15,8 +17,8 @@ private def real_path(image_file) path = image_file.value # Compute the real path to the image on the file stystem if the images_dir is set. - if Compass.configuration.images_dir - File.join(Compass.configuration.project_path, Compass.configuration.images_dir, path) + if Compass.configuration.images_path + File.join(Compass.configuration.images_path, path) else File.join(Compass.configuration.project_path, path) end @@ -29,7 +31,9 @@ private end def size - @dimensions ||= send("get_size_for_#{@file_type}") + @dimensions ||= send(:"get_size_for_#{@file_type}") + rescue NoMethodError + raise Sass::SyntaxError, "Unrecognized file type: #{@file_type}" end private @@ -39,12 +43,6 @@ private def get_size_for_gif size = IO.read(@file)[6..10].unpack('SS') - size.inspect - end - - def get_size_for_bmp - d = IO.read(@file)[14..28] - d[0] == 40 ? d[4..-1].unpack('LL') : d[4..8].unpack('SS') end def get_size_for_jpg diff --git a/test/compass_test.rb b/test/compass_test.rb index d0e43f23..665d0070 100644 --- a/test/compass_test.rb +++ b/test/compass_test.rb @@ -42,7 +42,7 @@ class CompassTest < Test::Unit::TestCase each_css_file(proj.css_path) do |css_file| assert_no_errors css_file, 'compass' end - assert_renders_correctly :reset, :layout, :utilities, :gradients + assert_renders_correctly :reset, :layout, :utilities, :gradients, :image_size end end diff --git a/test/fixtures/stylesheets/compass/100x150.jpg b/test/fixtures/stylesheets/compass/100x150.jpg new file mode 100644 index 00000000..70771213 Binary files /dev/null and b/test/fixtures/stylesheets/compass/100x150.jpg differ diff --git a/test/fixtures/stylesheets/compass/css/image_size.css b/test/fixtures/stylesheets/compass/css/image_size.css new file mode 100644 index 00000000..e74a195d --- /dev/null +++ b/test/fixtures/stylesheets/compass/css/image_size.css @@ -0,0 +1,15 @@ +.png { + width: 100px; + height: 150px; } + +.jpg { + width: 100px; + height: 150px; } + +.jpeg { + width: 100px; + height: 150px; } + +.gif { + width: 100px; + height: 150px; } diff --git a/test/fixtures/stylesheets/compass/images/100x150.gif b/test/fixtures/stylesheets/compass/images/100x150.gif new file mode 100644 index 00000000..b0368594 Binary files /dev/null and b/test/fixtures/stylesheets/compass/images/100x150.gif differ diff --git a/test/fixtures/stylesheets/compass/images/100x150.jpeg b/test/fixtures/stylesheets/compass/images/100x150.jpeg new file mode 100644 index 00000000..70771213 Binary files /dev/null and b/test/fixtures/stylesheets/compass/images/100x150.jpeg differ diff --git a/test/fixtures/stylesheets/compass/images/100x150.jpg b/test/fixtures/stylesheets/compass/images/100x150.jpg new file mode 100644 index 00000000..70771213 Binary files /dev/null and b/test/fixtures/stylesheets/compass/images/100x150.jpg differ diff --git a/test/fixtures/stylesheets/compass/images/100x150.png b/test/fixtures/stylesheets/compass/images/100x150.png new file mode 100644 index 00000000..5cec428d Binary files /dev/null and b/test/fixtures/stylesheets/compass/images/100x150.png differ diff --git a/test/fixtures/stylesheets/compass/sass/image_size.sass b/test/fixtures/stylesheets/compass/sass/image_size.sass new file mode 100644 index 00000000..982fceee --- /dev/null +++ b/test/fixtures/stylesheets/compass/sass/image_size.sass @@ -0,0 +1,12 @@ +.png + width= image_width("100x150.png") + height= image_height("100x150.png") +.jpg + width= image_width("100x150.jpg") + height= image_height("100x150.jpg") +.jpeg + width= image_width("100x150.jpeg") + height= image_height("100x150.jpeg") +.gif + width= image_width("100x150.gif") + height= image_height("100x150.gif")