Make :automatic_image_sizes work for absolute image paths

This commit is contained in:
Ben Hollis 2012-07-09 00:16:54 -07:00
parent 6dad42bc77
commit 4c5b614fe2

View file

@ -32,25 +32,25 @@ module Middleman
def image_tag(path, params={}) def image_tag(path, params={})
if !params.has_key?(:width) && !params.has_key?(:height) && !path.include?("://") if !params.has_key?(:width) && !params.has_key?(:height) && !path.include?("://")
params[:alt] ||= "" params[:alt] ||= ""
http_prefix = http_images_path rescue images_dir
begin real_path = path
real_path = File.join(source, images_dir, path) real_path = File.join(images_dir, real_path) unless real_path =~ %r{^/}
full_path = File.expand_path(real_path, root) full_path = File.join(source_dir, real_path)
http_prefix = http_images_path rescue images_dir
if File.exists? full_path if File.exists? full_path
dimensions = ::FastImage.size(full_path, :raise_on_failure => true) begin
params[:width] = dimensions[0] width, height = ::FastImage.size(full_path, :raise_on_failure => true)
params[:height] = dimensions[1] params[:width] = width
params[:height] = height
rescue
warn "Couldn't determine dimensions for image #{path}: #{$!.message}"
end end
rescue
# $stderr.puts params.inspect
end end
end end
super(path, params) super(path, params)
end end
end end
end end
end end
end end