attachment_fu resizing images already uploaded

hi, got a query.

i'm using the attachment_fu plugin to handle photo storage and that's
working fine, however now i've come to realise the initial size i set
the thumbnails and full photos isn't right, so i've changed the sizing
for future uploads but need to do this for past uploads.

any ideas how i'd do this, maybe in a migration or rake task?

i'm thinking i could build a task to reimport each full photo, after
which it deletes the original record, which is do-able.

just wondering if there's any magic method i'm missing to do it better?

appreciate any replies on this,

since you most likely have to do it only once,
you can do it in script/console.

Either write a small script for that task and start it in the console.
Or add a method to the model that contains the data and start that
within te console.

I eventually managed to get the time to put this one together, rake
script below...

#(run => 'rake images:[task]' or 'rake RAILS_ENV=production
images:[task]')

namespace :images do
  desc "list images"
  task(:list => :environment) do
    # list all images
    @photos = Image.find(:all, :conditions => ['parent_id is null'])
    @photos.each do |@photo|
      iFile = @photo.filename #@photo.public_filename
      iPath = RAILS_ROOT+"/public#{@photo.public_filename}"
      iID = @photo.id.to_s
      iUser_ID = @photo.user_id.to_s
      iWidth = @photo.width.to_s
      iHeight = @photo.height.to_s
      puts 'id:'+iID+' userid:'+iUser_ID+' width:'+iWidth+'
height:'+iHeight+' file:'+iFile+' path:'+iPath
    end
  end

  desc "add test image"
  task(:add_test => :environment) do
    # add image
    iFile = 'test2.jpg'
    iPath = '/var/www/apps/dates/test.jpg'
    @img = Image.new(:filename => iFile, :content_type => 'image/jpeg',
:temp_path => iPath, :user_id => 1).save!
  end

  desc "update test image"
  task(:update_test => :environment) do
    # update image
    iFile = 'test2.jpg'
    iPath = '/var/www/apps/dates/test2.jpg'
    @img = Image.find('101')
    if @img.update_attributes(:filename => iFile, :content_type =>
'image/jpeg', :temp_path => iPath, :user_id => 1)
      puts iFile + ' updated!'
    end
  end

  desc "reimage all existing images - test"
  task(:reimage_test => :environment) do
    # re-import all existing images - test
    @photos = Image.find(:all, :conditions => ['parent_id is null and
user_id = 2'])
    @photos.each do |@photo|
      iFile = @photo.filename
      iPath = RAILS_ROOT+"/public#{@photo.public_filename}"
      iType = @photo.content_type
      iUser_ID = @photo.user_id
      if @photo.update_attributes(:filename => iFile, :content_type =>
iType, :temp_path => iPath, :user_id => iUser_ID)
        puts iFile + ' updated!'
      end
    end
  end

  desc "reimage all existing images"
  task(:reimage => :environment) do
    # re-import all existing images
    @photos = Image.find(:all, :conditions => ['parent_id is null'])
    @photos.each do |@photo|
      iFile = @photo.filename
      iPath = RAILS_ROOT+"/public#{@photo.public_filename}"
      iType = @photo.content_type
      iUser_ID = @photo.user_id
      if @photo.update_attributes(:filename => iFile, :content_type =>
iType, :temp_path => iPath, :user_id => iUser_ID)
        puts iFile + ' updated!'
      end
    end
  end

end

it's a bit quick & dirty but it does the job.

all the best,

John.