How to deal with memory leaks in RMagick in Ruby?

后端 未结 5 675
梦谈多话
梦谈多话 2020-12-16 14:31

Im developing web-application with Merb and im looking for some safe and stable image processing library. I used to work with Imagick in php, then moved to ruby and start us

5条回答
  •  独厮守ぢ
    2020-12-16 15:22

    When using RMagick it's important to remember to destroy the image once you are done, otherwise you will fill up the /tmp dir when working with large sets of images. For example you must call destroy!

    require 'RMagick'
    
    Dir.foreach('/home/tiffs/') do |file|
        next if file == '.' or file == '..'
            image = Magick::Image.read(file).first
            image.format = "PNG"
            image.write("/home/png/#{File.basename(file, '.*')}.png")
            image.destroy!
    end
    

提交回复
热议问题