2010-09-06 21:48:25 -04:00
|
|
|
module Middleman::Features::AutomaticImageSizes
|
|
|
|
class << self
|
|
|
|
def registered(app)
|
|
|
|
require "middleman/features/automatic_image_sizes/fastimage"
|
2009-10-26 18:07:21 -04:00
|
|
|
|
2010-09-06 21:48:25 -04:00
|
|
|
app.helpers Helpers
|
|
|
|
end
|
|
|
|
alias :included :registered
|
|
|
|
end
|
|
|
|
|
|
|
|
module Helpers
|
|
|
|
def image_tag(path, params={})
|
|
|
|
if (!params[:width] || !params[:height]) && !path.include?("://")
|
|
|
|
params[:alt] ||= ""
|
|
|
|
http_prefix = settings.http_images_path rescue settings.images_dir
|
2009-11-22 18:37:11 -05:00
|
|
|
|
2010-09-06 21:48:25 -04:00
|
|
|
begin
|
2011-05-31 18:12:36 -04:00
|
|
|
real_path = File.join(settings.views, settings.images_dir, path)
|
2010-09-06 21:48:25 -04:00
|
|
|
if File.exists? real_path
|
|
|
|
dimensions = ::FastImage.size(real_path, :raise_on_failure => true)
|
|
|
|
params[:width] ||= dimensions[0]
|
|
|
|
params[:height] ||= dimensions[1]
|
2009-10-26 18:07:21 -04:00
|
|
|
end
|
2010-09-06 21:48:25 -04:00
|
|
|
rescue
|
2010-09-04 23:26:48 -04:00
|
|
|
end
|
2009-10-26 18:07:21 -04:00
|
|
|
end
|
2011-04-20 16:41:38 -04:00
|
|
|
|
|
|
|
super(path, params)
|
2009-10-26 18:07:21 -04:00
|
|
|
end
|
|
|
|
end
|
2010-09-06 21:48:25 -04:00
|
|
|
end
|