7

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

Mark Weston
  • 1,164
  • 10
  • 12
Sergey Kishenin
  • 5,099
  • 3
  • 30
  • 50

4 Answers4

10

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'
fabi
  • 2,978
  • 1
  • 19
  • 23
  • Thanks for your reply. Will try your fork asap. In current projects i started using rmagick instead. – Sergey Kishenin Oct 15 '11 at 04:01
  • 1
    My changes have been pulled and a new version of mini_magick has been released, so if you depend on the latest version of mini_magick the problems should go away. – fabi Jan 02 '12 at 11:04
  • Thank you! this helped me with that problem in newest minimagick (3.6.0). I won't use any other version now. :) – Dawid Woźniak Oct 10 '13 at 12:41
1

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.

Community
  • 1
  • 1
joslinm
  • 7,845
  • 6
  • 49
  • 72
1

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

Sergey Kishenin
  • 5,099
  • 3
  • 30
  • 50
  • actually `resize_to_fill` and resize_and_pad` have different effects. replacing one with another is just a way to have your application run at any price. – JNN Nov 20 '13 at 15:13
  • Agree. That was a temporary solution just to make it work. Hope that @fabi's solution works now – Sergey Kishenin Nov 21 '13 at 15:19
0

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]
Seb Wilgosz
  • 1,240
  • 15
  • 24