module Compass::Core::SassExtensions::Functions::ImageSize

Constants

KNOWN_TYPES

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/core/sass_extensions/functions/image_size.rb, line 11
def image_height(image_file)
  _, height = image_dimensions(image_file)
  number(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/core/sass_extensions/functions/image_size.rb, line 5
def image_width(image_file)
  width, _ = image_dimensions(image_file)
  number(width, "px")
end

Private Instance Methods

image_dimensions(image_file) click to toggle source
# File lib/compass/core/sass_extensions/functions/image_size.rb, line 50
def image_dimensions(image_file)
  image_file = image_file.respond_to?(:value) ? image_file.value : image_file
  options[:compass] ||= {}
  options[:compass][:image_dimensions] ||= {}
  options[:compass][:image_dimensions][image_file] = ImageProperties.new(image_path_for_size(image_file)).size
end
image_path_for_size(image_file) click to toggle source
# File lib/compass/core/sass_extensions/functions/image_size.rb, line 57
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/core/sass_extensions/functions/image_size.rb, line 64
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