1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00
middleman--middleman/lib/middleman/features/automatic_image_sizes.rb

31 lines
858 B
Ruby
Raw Normal View History

module Middleman::Features::AutomaticImageSizes
class << self
def registered(app)
require "middleman/features/automatic_image_sizes/fastimage"
2009-10-26 18:07:21 -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
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]
2009-10-26 18:07:21 -04:00
end
rescue
end
2009-10-26 18:07:21 -04:00
end
super(path, params)
2009-10-26 18:07:21 -04:00
end
end
end