0

在我的 Carrerwave 自定义处理方法中,我正在尝试使用该+repage选项。文档有点难找,但我发现我需要运行img.repage.+. 然而,这并没有奏效,因为它甚至没有尝试将选项转换为 +,而是将其保持在-repage原位并抛出了一个错误说明。然后我找到了一个页面,将其写成:

img.push '+repage'
img.+
img.repage

它使用了一个不同的示例(不使用 repage,而是使用带有两个参数的'+profile'。无论哪种方式它都不起作用......它现在告诉我undefined method 'gsub' for nil:NilClass并指向该img.+行。

这是我的方法:

def custom_thumbnail
    manipulate! do |img|
        img.distort :srt, -30
        img.repage.+
        img.crop "#{model.crop_w}x#{model.crop_h}+#{model.crop_x}+#{model.crop_y}"
        img
    end
end

其他人对此有任何运气吗?

编辑 - 直到控制器的完整堆栈跟踪以及更新的方法:

def custom_thumbnail
    manipulate! do |img|
        img.distort :srt, -30
        img.push '+repage'
        img.+
        img.repage
        img.crop "#{model.crop_w}x#{model.crop_h}+#{model.crop_x}+#{model.crop_y}"
        img.resize "150x150"
        img
    end
end

mini_magick (3.6.0) lib/mini_magick.rb:486:in `+'
mini_magick (3.6.0) lib/mini_magick.rb:343:in `block in method_missing'
mini_magick (3.6.0) lib/mini_magick.rb:361:in `call'
mini_magick (3.6.0) lib/mini_magick.rb:361:in `combine_options'
mini_magick (3.6.0) lib/mini_magick.rb:342:in `method_missing'
app/uploaders/wine_photo_uploader.rb:67:in `block in custom_thumbnail'
carrierwave (0.9.0) lib/carrierwave/processing/mini_magick.rb:262:in `manipulate!'
app/uploaders/wine_photo_uploader.rb:64:in `custom_thumbnail'
carrierwave (0.9.0) lib/carrierwave/uploader/processing.rb:85:in `block in process!'
carrierwave (0.9.0) lib/carrierwave/uploader/processing.rb:81:in `each'
carrierwave (0.9.0) lib/carrierwave/uploader/processing.rb:81:in `process!'
carrierwave (0.9.0) lib/carrierwave/uploader/callbacks.rb:18:in `block in with_callbacks'
carrierwave (0.9.0) lib/carrierwave/uploader/callbacks.rb:18:in `each'
carrierwave (0.9.0) lib/carrierwave/uploader/callbacks.rb:18:in `with_callbacks'
carrierwave (0.9.0) lib/carrierwave/uploader/cache.rb:122:in `cache!'
carrierwave (0.9.0) lib/carrierwave/uploader/store.rb:56:in `store!'
activesupport (4.0.0) lib/active_support/core_ext/object/try.rb:45:in `public_send'
activesupport (4.0.0) lib/active_support/core_ext/object/try.rb:45:in `try'
carrierwave (0.9.0) lib/carrierwave/uploader/versions.rb:281:in `block in store_versions!'
carrierwave (0.9.0) lib/carrierwave/uploader/versions.rb:281:in `each'
carrierwave (0.9.0) lib/carrierwave/uploader/versions.rb:281:in `store_versions!'
app/uploaders/wine_photo_uploader.rb:101:in `block in recreate_versions!'
app/uploaders/wine_photo_uploader.rb:98:in `each'
app/uploaders/wine_photo_uploader.rb:98:in `recreate_versions!'
app/controllers/wines_controller.rb:78:in `update'

最终解决方案!

这显然是正确的方法:

def custom_thumbnail
    manipulate! do |img|
        img.distort :srt, -30
        img.combine_options do |c|
            c.repage.+
            c.gravity :center
            c.crop "#{model.crop_w}x#{model.crop_h}+#{model.crop_x}+#{model.crop_y}"
            c.repage.+
        end
        img.resize "150x150"
        img
    end
end
4

1 回答 1

0

阅读源代码,我希望img.push '+repage'img.repage.+工作。后者似乎是官方支持的api。您原来的 custom_thumbnail 方法的跟踪是否相同?

也可以看看:

于 2013-10-28T19:20:00.500 回答