浮点域误差(无穷大)

发布于 2024-12-02 01:27:27 字数 173 浏览 7 评论 0原文

我使用 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 技术交流群。

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

发布评论

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

评论(4

瞄了个咪的 2024-12-09 01:27:27

我也有同样的问题。问题是mini_magick。如果运行 identify 的图像文件有错误,identify 会输出某种错误,例如

identify: Corrupt JPEG data: 7929 extraneous bytes before marker 0xed `image.jpg' @ warning/jpeg.c/EmitMessage/230.
11811 8665

mini_magick 尝试将错误消息解析为尺寸,结果为 <代码>0。这会导致除以零,从而导致您提到的异常。这就是为什么它只对某些图像失败的原因。

identify 有一个 -quiet 选项来关闭这些警告消息。我在 https://github.com/fschwahn/mini_magick 分叉了 mini_magick 并添加了安静选项。我希望这一更改能够被引入(或者问题将以更优雅的方式得到解决)。不过,现在您可以通过将以下内容添加到您的 Gemfile 来使用我的 fork:

gem 'mini_magick', :git => 'git://github.com/fschwahn/mini_magick.git'

I had the same problem. The problem is mini_magick. If the image file it runs identify on is erroneous, identify will output some kind of error, e.g.

identify: Corrupt JPEG data: 7929 extraneous bytes before marker 0xed `image.jpg' @ warning/jpeg.c/EmitMessage/230.
11811 8665

mini_magick tries to parse the error message as the dimension, and the result is 0. 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:

gem 'mini_magick', :git => 'git://github.com/fschwahn/mini_magick.git'
醉生梦死 2024-12-09 01:27:27

通过将 resize_and_fill 替换为 resize_and_pad 修复了该问题。还是不明白它的奇怪行为。

Fixed that with replacing resize_and_fill to resize_and_pad. Still don't understand its strange behavior.

浮生面具三千个 2024-12-09 01:27:27

我使用的是 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.

奢华的一滴泪 2024-12-09 01:27:27

当我为 pdf 文件生成图像缩略图时,我在最新的 gem 更新中遇到了此错误

此代码失败:

version :thumb do
  process :resize_to_fill => [260, 192]
  process :convert => :png
  process :set_content_type
  process :thumbnail_pdf
end

我通过替换行的顺序解决了它。关键是在调整大小之前,MiniMagic 应首先将缩略图转换为图像,然后尝试调整大小。

这是对我有用的解决方案。也许这对某人有帮助。

  process :convert => :png
  process :resize_to_fill => [260, 192]

I got this error with the newest gem update, when I generated an image thumbnail for my pdf file.

This code fails:

version :thumb do
  process :resize_to_fill => [260, 192]
  process :convert => :png
  process :set_content_type
  process :thumbnail_pdf
end

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.

  process :convert => :png
  process :resize_to_fill => [260, 192]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文