1

Railsアプリとgemのアップグレード、および以前の開発者からの文書化されていないコードが原因で、Railsアプリにバグを発見しました。処理された画像がたくさんありますが、attachment_fuを使用して正しくサイズ設定されていません。アップグレード以降にアップロードされたすべての画像は、正しくサイズ変更する必要があります。

フォルダ内のすべての画像を再処理して正しいサイズにサイズ変更するアイデアはありますか?これらすべてを手動で行う必要はありません。

ありがとう!!シンディ

4

3 に答える 3

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
于 2011-03-21T23:19:15.410 に答える
1

attachment_fuはimagemagicを使用しているので、(おそらく)すでにインストールされています。コマンドラインから使用する方法は次の とおりですhttp://www.imagemagick.org/script/command-line-processing.php

于 2010-05-13T22:01:15.263 に答える
0

Gistでこのコードを見つけました。AmazonS3でAttachment_fuリソースのサイズを変更するのはうまくいきました

GistのRakeタスクコード

于 2011-09-09T21:32:52.750 に答える