Module: Middleman::Extensions::AutomaticImageSizes::InstanceMethods
- Defined in:
- middleman-core/lib/middleman-core/extensions/automatic_image_sizes.rb
Overview
Automatic Image Sizes Instance Methods
Instance Method Summary (collapse)
-
- (String) image_tag(path, params = {})
Override default image_tag helper to automatically calculate and include image dimensions.
Instance Method Details
- (String) image_tag(path, params = {})
Override default image_tag helper to automatically calculate and include image dimensions.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'middleman-core/lib/middleman-core/extensions/automatic_image_sizes.rb', line 31 def image_tag(path, params={}) if !params.has_key?(:width) && !params.has_key?(:height) && !path.include?("://") params[:alt] ||= "" http_prefix = http_images_path rescue images_dir begin real_path = File.join(source, images_dir, path) full_path = File.(real_path, root) http_prefix = http_images_path rescue images_dir if File.exists? full_path dimensions = ::FastImage.size(full_path, :raise_on_failure => true) params[:width] = dimensions[0] params[:height] = dimensions[1] end rescue # $stderr.puts params.inspect end end super(path, params) end |