Carrierwave has a solution to that, pointed in the Readme:
Conditional versions
Occasionally you want to restrict the creation of versions on certain properties within the model or based on the picture itself.
class MyUploader < CarrierWave::Uploader::Base
version :human, :if => :is_human?
version :monkey, :if => :is_monkey?
version :banner, :if => :is_landscape?
protected
def is_human? picture
model.can_program?(:ruby)
end
def is_monkey? picture
model.favorite_food == 'banana'
end
def is_landscape? picture
image = MiniMagick::Image.open(picture.path)
image[:width] > image[:height]
end
end
Example
For example, to create thumbs only for images I adopted this option:
version :thumb, :if => :image? do
process :resize_to_fit => [200, 200]
end
protected
def image?(new_file)
new_file.content_type.start_with? 'image'
end
In this case make sure you include the MimeTypes:
include CarrierWave::MimeTypes