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
No EOL
858 B
Ruby
Executable file

module Middleman::Features::AutomaticImageSizes
class << self
def registered(app)
require "middleman/features/automatic_image_sizes/fastimage"
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
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
end
super(path, params)
end
end
end