【问题标题】:Need ideas for reprocessing images using attachment_fu需要使用 attachment_fu 重新处理图像的想法
【发布时间】:2010-05-13 21:50:49
【问题描述】:
我在 Rails 应用程序中发现了一个错误,原因是 Rails 应用程序和 gems 升级以及以前开发人员的未记录代码。我有很多图像已经过处理,但使用 attachment_fu 的大小不正确。升级后上传的所有图片都需要正确调整大小。
有没有人想重新处理文件夹中的所有图像并将它们调整为正确的大小?我不想必须手动完成所有这些操作。
谢谢!!
辛迪
【问题讨论】:
标签:
ruby-on-rails
ruby
scripting
attachment-fu
【解决方案1】:
我也遇到了同样的问题。这是我编写的一个小方法,用于重新生成全部内容,包括调整新缩略图的大小,以及纠正其他问题,例如损坏的父图像大小。
希望对您有所帮助!
山姆,
@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