Permalink
Browse files

Delete temp file after manipulate

  • Loading branch information...
1 parent 8b44eb2 commit 3a1ec201bac54d796ea15ba30eb0545fd57df417 @dimko dimko committed Feb 17, 2014
Showing with 9 additions and 4 deletions.
  1. +9 −4 lib/carrierwave/processing/mini_magick.rb
@@ -258,10 +258,15 @@ def resize_and_pad(width, height, background=:transparent, gravity='Center')
def manipulate!
cache_stored_file! if !cached?
image = ::MiniMagick::Image.open(current_path)
- image.format(@format.to_s.downcase) if @format
- image = yield(image)
- image.write(current_path)
- image.run_command("identify", current_path)
+
+ begin
+ image.format(@format.to_s.downcase) if @format
+ image = yield(image)
+ image.write(current_path)
+ image.run_command("identify", current_path)
+ ensure
+ image.destroy!
+ end
rescue ::MiniMagick::Error, ::MiniMagick::Invalid => e
raise CarrierWave::ProcessingError, I18n.translate(:"errors.messages.mini_magick_processing_error", :e => e, :default => I18n.translate(:"errors.messages.mini_magick_processing_error", :e => e, :locale => :en))
end

0 comments on commit 3a1ec20

Please sign in to comment.