Module: Dimensions::Rails::Helper

Defined in:
lib/dimensions-rails.rb

Instance Method Summary collapse

Instance Method Details

#image_tag(source, options = {}) ⇒ Object

Use dimensions by @sstephenson to add automatic images size and improve browser rendering.

How this improves browser rendering? developers.google.com/speed/docs/best-practices/rendering#SpecifyImageDimensions



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dimensions-rails.rb', line 17

def image_tag source, options = {}
  disable_dimensions = options.delete(:dimensions) == false

  unless disable_dimensions or options[:size] or options[:width] or options[:height]
    fs_path = ::Rails.application.assets.find_asset(source)
    fs_path = fs_path.present? ? fs_path.pathname : File.join(::Rails.public_path, source)

    if fs_path.present? and File.exist? fs_path
      options[:width], options[:height] = ::Dimensions.dimensions(fs_path)
    end
  end
  super
end