1

I want my app to be able to tell the difference between a horizontal image and a vertical image, and resize it accordingly when the user uploads it.

I was able to get it working with minimagick but for some reason it does not work the same with Rmagick below is the logic I used for minimagick (in the initializers/carrierwave.rb)

I need to switch to rmagick for some other features I'd like to use

require 'carrierwave/orm/activerecord'

module CarrierWave
    module RMagick
        def from_orientation(portrait, landscape)
            manipulate! do |img|
                if img[:width] > img[:height]
                    width, height = landscape
                else
                    width, height = portrait
                end
                img.resize "#{width}x#{height}>"
                img
            end
        end
    end
end

As you can see i changed the module from minimagick to rmagick I also included the proper gem as well. This is the error i get which makes me wonder what exactly I'm doing wrong:

undefined method `>' for nil:NilClass 

This confuses me because the greater than bracket is obviously not a class.

Thank you for all your help in advance!

4

1 回答 1

1

问题是 RMagick 和 MiniMagick 有不同的接口。您不能只是切换库并期望相同的代码可以工作。

您的错误告诉您问题是 img[:width] 为零。这是有道理的,因为 img[:width] 不是你可以用 RMagick 做的。img.columns应该给出宽度,同样img.rows给出高度。

我建议查看 RMagick 的文档。

于 2013-05-31T16:26:40.277 回答