Module: Dimensions::Rails::Helper
- Defined in:
- lib/dimensions-rails.rb
Instance Method Summary collapse
-
#image_tag(source, options = {}) ⇒ Object
Use dimensions by @sstephenson to add automatic images size and improve browser rendering.
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, = {} disable_dimensions = .delete(:dimensions) == false unless disable_dimensions or [:size] or [:width] or [: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 [:width], [:height] = ::Dimensions.dimensions(fs_path) end end super end |