Reputation: 687
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
Upvotes: 1
Views: 389
Reputation: 527
I found this bit of code on Gist. It worked nicely for me to resize Attachment_fu resources on Amazon S3
Upvotes: 0
Reputation: 21
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
Upvotes: 2
Reputation: 1459
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
Upvotes: 1