i'm using this plugin for files and images uploads.
it has a very useful feature that generate thumbnails of every
uploaded image, based on the geometry given in the model definition.
now i want to change the size of one of the thumbnail: how can i re-
generate them for the already saved image?
why don't you just write a migration that loops all of those objects
with the old thumbnail-information and call the method that generates
the thumbnails again.
i'd like to add: i don't know your app and i don't use attachment_fu
either. thus, the line above is obviously not working. it's just to
give you an idea.
I use a method that rebuilds in my attachment model class:
# use attachment_fu protected methods to remake thumbs
def remake_thumbnails!
self.thumbnails.each {|thumb| thumb.destroy}
temp_file = create_temp_file
attachment_options[:thumbnails].each do |suffix, size|
self.create_or_update_thumbnail(temp_file, suffix, *size)
end
end
If you want a rake task, just loop through all your attachment records
and call it. I'm using something similar to this:
namespace :images do
desc "Rebuild all thumb images made by attachment_fu"
task :rebuild_thumbnails => :environment do
conditions = "(whatever you need)"
count = Image.count(:all, :conditions => conditions) # image is an
attachment_fu model
done = 0
chunk_size = 500
(0...(count/chunk_size)).each do |i|
Image.find(:all, :offset => i*chunk_size, :limit =>
chunk_size, :conditions => conditions).each do |image|
done = done + 1
# next if image.id < 46520 # to resume a stopped run
image.remake_thumbnails!
percent = "%.2f" % ((done/count.to_f)*100)
puts "#{i.id} #{percent}% done"
end
end
end