Carrierwave版本取决于文件扩展名

时间:2013-11-17 23:30:40

标签: ruby-on-rails carrierwave

我hava uploader

class PimageUploader < CarrierWave::Uploader::Base

  include CarrierWave::MiniMagick

  storage :webdav if Rails.env.production?
  storage :file if Rails.env.development?

  version :preview do
    process resize_to_limit: [640, 640]
  end

  version :post do
    process resize_to_limit: [640, nil]
  end

  version :thumb do
    process resize_to_limit: [150, nil]
  end

end

帮助我,我需要使用扩展程序gif make only thumb version。

1 个答案:

答案 0 :(得分:2)

尝试使用以下内容:

  version :thumb, :if => :is_gif?

  protected
  def is_gif?(picture)
    picture.extension.to_s.downcase == 'gif'
  end