문제

I discovered a bug in my Rails app due to Rails app and gems upgrades and undocumented code from the previous developers. I have a lot of images that have been processed, but not sized correctly using attachment_fu. All of the images that were uploaded since the upgrade need to be resized correctly.

Does anyone have any ideas to reprocess all of the images within the folders and resize them to the correct sizes? I'd hate to have to do these all manually.

THANKS!! Cindy

도움이 되었습니까?

해결책

attachment_fu uses imagemagic, so you (probably) already have it installed. Here's how to use it via command line http://www.imagemagick.org/script/command-line-processing.php

다른 팁

I've had the same problem. This is a little method I wrote to go and re-generate the whole lot, including resizing to new thumbnails, and correcting other issues like corrupt parent image sizes.

Hope it helps! Sam, @samotage

def self.rebuild_thumbnails
    images = UserUpload.find(:all)
    processed = 0
    not_processed = 0
    puts "---------------------------------"
    puts "rebuilding thumbnails"
    puts " "
    images.each do |image|
      this_type = image.type.to_s
      puts "processing upload: #{image.id} of type: #{this_type}"
      if image.thumbnailable?
        puts "bingo! It's thumbnailable, now rebuilding."
        image.thumbnails.each { |thumbnail| thumbnail.destroy }
        puts "Re-generating main image witdh and height"
        image.save
        puts "Regenerating thumbnails..."
        image.attachment_options[:thumbnails].each { |suffix, size| image.create_or_update_thumbnail(image.create_temp_file, suffix, *size) }
        processed += 1
        puts "Now processed #{processed} images"
        puts ""
      else
        not_processed += 1
      end
    end
    return processed
  end

I found this bit of code on Gist. It worked nicely for me to resize Attachment_fu resources on Amazon S3

Rake task code on Gist

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top