class Compass::SassExtensions::Functions::ImageSize::ImageProperties
Public Class Methods
new(file)
click to toggle source
# File lib/compass/sass_extensions/functions/image_size.rb, line 15 def initialize(file) @file = (file.respond_to?(:to_path) ? file.to_path : file) @file_type = File.extname(@file)[1..-1] end
Public Instance Methods
size()
click to toggle source
# File lib/compass/sass_extensions/functions/image_size.rb, line 20 def size @dimensions ||= send(:"get_size_for_#{@file_type}") rescue NoMethodError raise Sass::SyntaxError, "Unrecognized file type: #{@file_type}" end
Private Instance Methods
get_size_for_gif()
click to toggle source
# File lib/compass/sass_extensions/functions/image_size.rb, line 31 def get_size_for_gif File.open(@file, "rb") {|io| io.read}[6..10].unpack('SS') end
get_size_for_jpeg()
click to toggle source
# File lib/compass/sass_extensions/functions/image_size.rb, line 39 def get_size_for_jpeg jpeg = JPEG.new(@file) [jpeg.width, jpeg.height] end
get_size_for_jpg()
click to toggle source
# File lib/compass/sass_extensions/functions/image_size.rb, line 35 def get_size_for_jpg get_size_for_jpeg end
get_size_for_png()
click to toggle source
# File lib/compass/sass_extensions/functions/image_size.rb, line 27 def get_size_for_png File.open(@file, "rb") {|io| io.read}[0x10..0x18].unpack('NN') end