Carrierwave +repage option not working

旧城冷巷雨未停 提交于 2019-12-11 19:51:32

问题


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

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.

This is my method:

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

Anyone else have any luck with this?

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'

Final Solution!

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

回答1:


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?

See also:

  • 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


来源:https://stackoverflow.com/questions/19626679/carrierwave-repage-option-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!