module Compass::SassExtensions::Functions::ImageSize

Public Instance Methods

image_height(image_file) click to toggle source

Returns the height of the image relative to the images directory

# File lib/compass/sass_extensions/functions/image_size.rb, line 9
def image_height(image_file)
  _, height = image_dimensions(image_file)
  Sass::Script::Number.new(height, ["px"])
end
image_width(image_file) click to toggle source

Returns the width of the image relative to the images directory

# File lib/compass/sass_extensions/functions/image_size.rb, line 3
def image_width(image_file)
  width, _ = image_dimensions(image_file)
  Sass::Script::Number.new(width,["px"])
end

Private Instance Methods

image_dimensions(image_file) click to toggle source
# File lib/compass/sass_extensions/functions/image_size.rb, line 47
def image_dimensions(image_file)
  options[:compass] ||= {}
  options[:compass][:image_dimensions] ||= {}
  options[:compass][:image_dimensions][image_file.value] = ImageProperties.new(image_path_for_size(image_file.value)).size
end
image_path_for_size(image_file) click to toggle source
# File lib/compass/sass_extensions/functions/image_size.rb, line 53
def image_path_for_size(image_file)
  if File.exists?(image_file)
    return image_file 
  end
  real_path(image_file)
end
real_path(image_file) click to toggle source
# File lib/compass/sass_extensions/functions/image_size.rb, line 60
def real_path(image_file)
  # Compute the real path to the image on the file stystem if the images_dir is set.
  if Compass.configuration.images_path
    File.join(Compass.configuration.images_path, image_file)
  else
    File.join(Compass.configuration.project_path, image_file)
  end
end