Carrierwave + repage选项不起作用 [英] Carrierwave +repage option not working

查看:163
本文介绍了Carrierwave + repage选项不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my Carrerwave custom process method, I'm attempting to use the +repage option. Documentation was kind of hard to come across, but I found that I needed to run img.repage.+. However that didn't work out as it didn't even try to convert the option to +, but kept it at -repage and threw an error illustrating as much. Then I found a page which illustrated to write it out as:

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

它使用了另一个例子(不使用重复,但使用' + profile'有两个参数。无论哪种方式它都不起作用......它现在告诉我未定义的方法'gsub'为nil:NilClass 并指向 img。+ line。

It used a different example (not using repage, but using '+profile' with two arguments. Either way it doesn't work...it's now telling me undefined method 'gsub' for nil:NilClass and pointing to the img.+ line.

这是我的方法:

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

其他人有运气吗?

编辑 - 全栈跟踪直到控制器和更新的方法:

EDIT - Full stack trace up until controller along with updated method:

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'

最终解决方案!

这是明确这样做的正确方法:

This is the proper way to do it apparently:

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


推荐答案

阅读来源,我希望 img.push'+ repage' img.repage。+ 上班。后者似乎是官方支持 API。原始custom_thumbnail方法的跟踪是否相同?

Reading the source, I'd expect img.push '+repage' or img.repage.+ to work. The latter seems to be the officially supported api. Is the trace the same for your original custom_thumbnail method?

另请参阅:

  • https://github.com/minimagick/minimagick/pull/115/files
  • https://github.com/minimagick/minimagick/issues/107#issuecomment-11034818
  • https://github.com/minimagick/minimagick/blob/v3.6.0/test/command_builder_test.rb#L38

这篇关于Carrierwave + repage选项不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆