Skip to content

Commit

Permalink
Don't resize an asset to the same dimensions multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
zmbush committed Mar 7, 2015
1 parent 3db41da commit ffab29f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/jekyll/assets_plugin/patches/asset_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ def basename
end

def resize(dimensions, outdir)
outfile = "#{basename}-#{dimensions}#{extname}".gsub(/%/, "P")
img = MiniMagick::Image.read(to_s, extname)
img.resize dimensions
img.write "#{outdir}/#{outfile}"
@outfiles ||= {}
if !@outfiles.has_key?(dimensions)
@outfiles[dimensions] = "#{basename}-#{dimensions}#{extname}".gsub(/%/, "P")
img = MiniMagick::Image.read(to_s, extname)
img.resize dimensions
img.write "#{outdir}/#{@outfiles[dimensions]}"
end

outfile
@outfiles[dimensions]
end
end
end
Expand Down

0 comments on commit ffab29f

Please sign in to comment.