Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tempfile never deleted #447

Open
kaluznyo opened this issue Feb 20, 2018 · 3 comments
Open

Tempfile never deleted #447

kaluznyo opened this issue Feb 20, 2018 · 3 comments

Comments

@kaluznyo
Copy link

kaluznyo commented Feb 20, 2018

I use Minimagick and my folder /tmp don't stop growing with file like mini_magick20180220-95997-y59ae0.jpg.

I use minimagick like this :

begin
  image = MiniMagick::Image.open("#{absolute_path}/#{file}")
  image.thumbnail(THUMBNAILS_DIMENSION)
  image.write "#{thumbnails_absolute_path}/#{file}"
rescue StandardError

end

I miss something ?

@kaluznyo kaluznyo changed the title Tempfile never delete Tempfile never deleted Feb 20, 2018
@janko
Copy link
Member

janko commented Apr 3, 2018

MiniMagick currently doesn't delete the tempfile after Image#write, though it probably should. For now you can call image.destroy! after writing:

begin
  image = MiniMagick::Image.open("#{absolute_path}/#{file}")
  image.thumbnail(THUMBNAILS_DIMENSION)
  image.write "#{thumbnails_absolute_path}/#{file}"
rescue StandardError
  # ...
ensure 
  image.destroy!
end

@ThomasSevestre
Copy link

You could add a block notation that destroy the tempfile :

MiniMagick::Image.open("#{absolute_path}/#{file}") do |image|
  image.thumbnail(THUMBNAILS_DIMENSION)
  image.write "#{thumbnails_absolute_path}/#{file}"
end

@agusbrand
Copy link

agusbrand commented Aug 3, 2022

@ThomasSevestre MiniMagick::Image.open does not accept a block notation 🤔

https://www.rubydoc.info/gems/mini_magick/MiniMagick%2FImage.open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants