2010-05-13 69 views
1

由于Rails应用程序和宝石升级以及以前开发人员的未公开文档,我发现了Rails应用程序中的一个错误。我有很多已处理的图像,但未使用attachment_fu正确确定大小。自升级以来上传的所有图像都需要正确调整大小。需要想法使用attachment_fu来重新处理图像

有没有人有任何想法来重新处理文件夹内的所有图像,并将它们调整到正确的尺寸?我讨厌必须手动完成这些。

谢谢! Cindy

回答

1

attachment_fu使用imagemagic,所以你(可能)已经安装了它。以下是如何通过命令行使用它的方法http://www.imagemagick.org/script/command-line-processing.php

+0

其实,我使用imagescience的文件处理。 – cswebgrl 2010-05-13 22:27:49

+0

我认为annaswims仍然有正确的方法,从命令行修改它们,这里有体面的imagecience方向:http://seattlerb.rubyforge.org/ImageScience.html – 2010-05-13 23:11:06

2

我遇到了同样的问题。这是我写的一个小方法,可以重新生成所有内容,包括调整大小以适应新的缩略图,以及纠正其他问题,如损坏的父图像大小。

希望它有帮助! 山姆, @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