需要使用 Attachment_fu 重新处理图像的想法

发布于 2024-09-01 11:14:19 字数 198 浏览 4 评论 0原文

由于 Rails 应用程序和 gems 升级以及以前的开发人员未记录的代码,我在我的 Rails 应用程序中发现了一个错误。我有很多已经处理过的图像,但使用attachment_fu 的尺寸不正确。自升级以来上传的所有图像都需要正确调整大小。

有谁有任何想法来重新处理文件夹中的所有图像并将其调整为正确的尺寸?我不想手动完成这些工作。

谢谢!! 辛迪

I discovered a bug in my Rails app due to Rails app and gems upgrades and undocumented code from the previous developers. I have a lot of images that have been processed, but not sized correctly using attachment_fu. All of the images that were uploaded since the upgrade need to be resized correctly.

Does anyone have any ideas to reprocess all of the images within the folders and resize them to the correct sizes? I'd hate to have to do these all manually.

THANKS!!
Cindy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

卖梦商人 2024-09-08 11:14:19

我也遇到过同样的问题。这是我编写的一个小方法,用于重新生成全部内容,包括调整新缩略图的大小,以及纠正其他问题,例如损坏的父图像大小。

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

I've had the same problem. This is a little method I wrote to go and re-generate the whole lot, including resizing to new thumbnails, and correcting other issues like corrupt parent image sizes.

Hope it helps!
Sam,
@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
七七 2024-09-08 11:14:19

Attachment_fu 使用 imagemagic,因此您(可能)已经安装了它。以下是如何通过命令行使用它 http://www.imagemagick.org/脚本/命令行处理.php

attachment_fu uses imagemagic, so you (probably) already have it installed. Here's how to use it via command line http://www.imagemagick.org/script/command-line-processing.php

旧竹 2024-09-08 11:14:19

我在 Gist 上找到了这段代码。它对我来说在 Amazon S3 上调整 Attachment_fu 资源的大小非常有效

Rake 任务代码在 Gist

I found this bit of code on Gist. It worked nicely for me to resize Attachment_fu resources on Amazon S3

Rake task code on Gist

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文