Reprocessing images of different versions in Carrierwave

前端 未结 5 1418
甜味超标
甜味超标 2021-02-02 14:12

Using Carrierwave, I created 3 versions of an avatar - an original, a small_thumb and a large_thumb using the following lines:

process :resize_to_limit => [40         


        
5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-02 15:05

    This HowTo was most helpful for me (even if I don't use fog):

    https://github.com/carrierwaveuploader/carrierwave/wiki/How-to:-Recreate-and-reprocess-your-files-stored-on-fog

    I added a reprocess method on my model and then called it in for each loop in my rake task:

      def reprocess
        begin
          self.process_photo_upload = true
          self.photo.cache_stored_file!
          self.photo.retrieve_from_cache!(photo.cache_name)
          self.photo.recreate_versions!
          self.save!
        rescue => e
          STDERR.puts  "ERROR: MyModel: #{id} -> #{e.to_s}"
        end
      end
    

    Rake:

    task :reprocess_photos => :environment do MyModel.all.each{|mm| mm.reprocess} end

    PS: Rails 4.2

提交回复
热议问题