Carrierwave +repage option not working
Asked Answered
F

1

0

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
Fornix answered 28/10, 2013 at 3:16 Comment(1)
Could you post a stack trace?Preeminent
P
0

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:

Preeminent answered 28/10, 2013 at 19:20 Comment(1)
Rereading it closely, I see they put it inside of combine_options and that's what I needed to do to get it to work. The same issue happened with attempting to set the gravity. So it wouldn't be "img", it would be img.combine_options do |c| c.repage.+ end. Thanks!Fornix

© 2022 - 2024 — McMap. All rights reserved.