2010-05-13 40 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