Sha256: bfd4877a1099e929017dcf51aad8b0f01a62bd2b3226bc2baea56c158640cb22

Contents?: true

Size: 901 Bytes

Versions: 8

Compression:

Stored size: 901 Bytes

Contents

namespace :images do

  desc "Regenerate all thumbnails. Useful for when you've changed size or cropping on the images after images have been uploaded."
  task :regenerate => :environment do
    thumbnails_size = Image.count(:conditions => "parent_id IS NOT NULL")
    puts "Preparing to delete #{thumbnails_size} generated thumbnails"
        
    if Image.destroy_all("parent_id IS NOT null")
      puts "--> #{thumbnails_size} thumbnails deleted"
    else
      puts "There may have been a problem deleting the thumbnails."
    end
    
    originals = Image.originals
    puts "Preparing to regenerate thumbnails for #{originals.size} images"
    
    originals.each do |image|
      begin
        image.save
      rescue Exception => e  
        puts "--> ERROR image #{image.id} could not be saved because #{e.message}"
      end
    end
    
    puts "Image regeneration complete."
  end
  
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
refinerycms-0.9.3 vendor/plugins/images/lib/tasks/images.rake
refinerycms-0.9.2.2 vendor/plugins/images/lib/tasks/images.rake
refinerycms-0.9.2.1 vendor/plugins/images/lib/tasks/images.rake
refinerycms-0.9.2 vendor/plugins/images/lib/tasks/images.rake
refinerycms-0.9.1.2 vendor/plugins/images/lib/tasks/images.rake
refinerycms-0.9.1.1 vendor/plugins/images/lib/tasks/images.rake
refinerycms-0.9.1 vendor/plugins/images/lib/tasks/images.rake
refinerycms-0.9.0 vendor/plugins/images/lib/tasks/images.rake