attachment_fu, how to regenerate thumbnails

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?

i found this http://github.com/kete/kete/blob/master/lib/tasks/tools.rake but i don't understand how to use it.

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.

like this:

MyModel.find_all_with_thumbnails.each(&:generate_thumbnail)

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

Hello!

This is old thread but i need some help!

I’d like to take foz’s solution for my project using attachment_fu.

I am going to make link to remake thumbs in my view, and i don’t need to rake task.

But I don’t know where I should put ‘remake_thumbnails!’ method in.

I’ve tried to put the method in ‘attachment_fu.rb’, but it’s not working.

Should I put it in my upload model or wherelse?

And how can I call this method from view or controller?

I am a really beginner in web development using Rails and Ruby.

it will many thanks if you help me.

2009년 11월 30일 월요일 오후 1시 15분 33초 UTC+9, foz 님의 말: