Module: Middleman::Features::AutomaticImageSizes::Helpers

Defined in:
lib/middleman/features/automatic_image_sizes.rb

Instance Method Summary collapse

Instance Method Details

#image_tag(path, params = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/middleman/features/automatic_image_sizes.rb', line 12

def image_tag(path, params={})
  if (!params[:width] || !params[:height]) && !path.include?("://")
    params[:alt] ||= ""
    http_prefix = settings.http_images_path rescue settings.images_dir

    begin
      real_path = File.join(settings.public, settings.images_dir, path)
      if File.exists? real_path
        dimensions = ::FastImage.size(real_path, :raise_on_failure => true)
        params[:width]  ||= dimensions[0]
        params[:height] ||= dimensions[1]
      end
    rescue
    end

    super(asset_url(path, http_prefix), params)
  else
    super(path, params)
  end
end