identifier :imgresize
type :binary
+ def fetch_from_cache(filename, params)
+ return unless params[:cache]
+
+ cachefile = File.join(@config[:output_dir], params[:cache])
+ begin
+ s = File.stat(cachefile)
+ rescue Errno::ENOENT
+ return
+ end
+
+ return unless s.mtime >= File.stat(filename).mtime
+
+ begin
+ File.link(cachefile, output_filename)
+ rescue
+ FileUtils.copy_file(cachefile, output_filename)
+ end
+
+ return true
+ end
+
def run(filename, params = {})
w = if params[:width] then params[:width].to_i end
h = if params[:height] then params[:height].to_i end
end
args << output_filename
- system('gm', 'convert', *args)
+ unless fetch_from_cache(filename, params)
+ system('gm', 'convert', *args)
+ end
end
end