在 Ruby on Rails 应用程序中使用 MiniMagick 时,临时文件在哪里?

发布于 2024-11-17 12:55:31 字数 1055 浏览 2 评论 0原文

我正在使用 MiniMagick 对通过多部分表单上传的图像执行一些图像大小调整。我需要从最初上传的文件生成一些不同类型的图像。以下是执行图像处理的代码:

// Generates a thumbnail image
mm = MiniMagick::Image.open(Rails.root.join('public', 'uploads', new_url))
mm.resize(thumbnail_dimensions.join("x"))
mm.write(Rails.root.join('public', 'uploads', "t_"+new_url))

// Generates cropped version
mm_copy = MiniMagick::Image.open(Rails.root.join('public', 'uploads', new_url))
mm_copy.crop('200x200')
mm_copy.write(Rails.root.join('public', 'uploads', "c_"+new_url))

new_urlpublic 文件夹中图像的路径。缩略图例程运行完美。当应用程序开始处理裁剪后的版本时,事情就开始出现问题,我一生都无法弄清楚。从这段代码中我收到以下错误:

No such file or directory - /tmp/mini_magick20110627-10055-2dimyl-0.jpg

我读了一些有关 Rails 中垃圾收集器可能出现的竞争条件的内容,但我无法解决该问题。我也从控制台尝试了此操作,并且可以创建 MiniMagick 实例,但也收到 No such file 错误。目前,我不知道该去哪里,所以我希望这里有人能提供一些有用的建议。感谢您的帮助!

详细信息

  • 操作系统:Ubuntu (Lucid Lynx)
  • Rails 版本:3.0.7
  • Ruby 版本:1.8.7
  • MiniMagick 版本:3.3

I'm using MiniMagick to perform some image resizing on images uploaded through a multi-part form. I need to generate a few different types of images from the originally uploaded file. Here's the code that's performing the image processing:

// Generates a thumbnail image
mm = MiniMagick::Image.open(Rails.root.join('public', 'uploads', new_url))
mm.resize(thumbnail_dimensions.join("x"))
mm.write(Rails.root.join('public', 'uploads', "t_"+new_url))

// Generates cropped version
mm_copy = MiniMagick::Image.open(Rails.root.join('public', 'uploads', new_url))
mm_copy.crop('200x200')
mm_copy.write(Rails.root.join('public', 'uploads', "c_"+new_url))

new_url is the path to the image in the public folder. The thumbnail routine works perfectly. When the app goes to start processing the cropped version, that is where things start breaking and I can't for the life of me figure it out. I receive the following error when from this code:

No such file or directory - /tmp/mini_magick20110627-10055-2dimyl-0.jpg

I read some stuff about possible race conditions with the garbage collector in Rails but I wasn't able to resolve the issue. I tried this from the console as well and can create MiniMagick instances but receive the No such file error there as well. At this point, I have no idea where to go so I'm hoping someone here has some helpful suggestions. Thanks for your help!

Details:

  • OS: Ubuntu (Lucid Lynx)
  • Rails Version: 3.0.7
  • Ruby Version: 1.8.7
  • MiniMagick Version: 3.3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏夜暖风 2024-11-24 12:55:31

你安装了ImageMagick吗?
如果不,
尝试sudo apt-get install ImageMagick
然后重新启动你的 webrick 服务器

Did you installed ImageMagick?
If not,
try sudo apt-get install ImageMagick,
and then restart your webrick server

何止钟意 2024-11-24 12:55:31

这可能是这里提到的竞争条件:

https ://ar-code.lighthouseapp.com/projects/35/tickets/6-race-condition-with-temp_file

这里有一个修复:

http://rubyforge.org/tracker/index .php?func=detail&aid=9417&group_id=1358&atid=5365

或者,也许更容易,你可以尝试这个:

// Generates a thumbnail image
mm = MiniMagick::Image.open(Rails.root.join('public', 'uploads', new_url))
mm_copy = mm.clone   # clone the opened Image, instead of re-opening it

mm.resize(thumbnail_dimensions.join("x"))
mm.write(Rails.root.join('public', 'uploads', "t_"+new_url))

// Generates cropped version
mm_copy.crop('200x200')
mm_copy.write(Rails.root.join('public', 'uploads', "c_"+new_url))

it's probably the race condition which is mentioned here:

https://ar-code.lighthouseapp.com/projects/35/tickets/6-race-condition-with-temp_file

here's one fix:

http://rubyforge.org/tracker/index.php?func=detail&aid=9417&group_id=1358&atid=5365

alternatively, and probably easier, you could try this:

// Generates a thumbnail image
mm = MiniMagick::Image.open(Rails.root.join('public', 'uploads', new_url))
mm_copy = mm.clone   # clone the opened Image, instead of re-opening it

mm.resize(thumbnail_dimensions.join("x"))
mm.write(Rails.root.join('public', 'uploads', "t_"+new_url))

// Generates cropped version
mm_copy.crop('200x200')
mm_copy.write(Rails.root.join('public', 'uploads', "c_"+new_url))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文