浮点域误差(无穷大)
我使用 Carrierwave 和 mini_magick 上传图像。在开发中,一切都很好,但在生产中,当我尝试上传图像时,它会引发FloatDomainError (Infinity)
。我有几个项目托管在同一台服务器上,上传一切正常。 我使用 Rails 3.0.10。 我有什么想法可以解决它吗?谢谢
I use carrierwave and mini_magick to upload images. In development everything is fine, but in production it raises FloatDomainError (Infinity)
when i try to upload an image. I have several projects hosted at the same server and everything is fine with uploading.
I use Rails 3.0.10.
Any ideas how can i fix it? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(4)
我也有同样的问题。问题是
mini_magick
。如果运行identify
的图像文件有错误,identify 会输出某种错误,例如mini_magick
尝试将错误消息解析为尺寸,结果为 <代码>0。这会导致除以零,从而导致您提到的异常。这就是为什么它只对某些图像失败的原因。identify
有一个-quiet
选项来关闭这些警告消息。我在 https://github.com/fschwahn/mini_magick 分叉了 mini_magick 并添加了安静选项。我希望这一更改能够被引入(或者问题将以更优雅的方式得到解决)。不过,现在您可以通过将以下内容添加到您的 Gemfile 来使用我的 fork:I had the same problem. The problem is
mini_magick
. If the image file it runsidentify
on is erroneous, identify will output some kind of error, e.g.mini_magick
tries to parse the error message as the dimension, and the result is0
. This results in a division by zero which results in the exception you mentioned. This is the reason why it only fails with some images.identify
has a-quiet
options to turn off these warning messages. I have forked mini_magick at https://github.com/fschwahn/mini_magick and added the quiet option. I hope this change will be pulled in (or the problem will be fixed in a more elegant way). However, for now you can use my fork by adding the following to your Gemfile:通过将
resize_and_fill
替换为resize_and_pad
修复了该问题。还是不明白它的奇怪行为。Fixed that with replacing
resize_and_fill
toresize_and_pad
. Still don't understand its strange behavior.我使用的是 Ubuntu Imagemagick 软件包版本 6.7。我按照此处的说明升级到 6.8: https://askubuntu.com/questions/267746/how-can-i-install-the-latest-upstream-version-of-imagemagick-without-compiling 和它起作用了。
I was using the Ubuntu Imagemagick package version 6.7. I upgraded to 6.8 following the instructions here: https://askubuntu.com/questions/267746/how-can-i-install-the-latest-upstream-version-of-imagemagick-without-compiling and it worked.
当我为 pdf 文件生成图像缩略图时,我在最新的 gem 更新中遇到了此错误。
此代码失败:
我通过替换行的顺序解决了它。关键是在调整大小之前,
MiniMagic
应首先将缩略图转换为图像,然后尝试调整大小。这是对我有用的解决方案。也许这对某人有帮助。
I got this error with the newest gem update, when I generated an image thumbnail for my pdf file.
This code fails:
I solved it by replacing the order of the lines. The key was that before resizing
MiniMagic
should first convert thumbnail to image and after that should try to resize.Here is solution which worked for me. Maybe it'll help for someone.