1

所以我试图让图像裁剪在 Amazon S3 上工作,我有以下功能

def update_attributes(att)
  scaled_img = Magick::ImageList.new(self.photo.to_file)
  orig_img = Magick::ImageList.new(self.photo.to_file(:original))
  scale = orig_img.columns.to_f / scaled_img.columns

  args = [ att[:x1], att[:y1], att[:width], att[:height] ]
  args = args.collect { |a| a.to_i * scale }

  orig_img.crop!(*args)
  orig_img.write(self.photo.to_file(:original))

  self.photo.reprocess!
  self.save

  super(att)
end

离线工作正常,我在 Heroku + S3 上部署的所有更改都是“to_file”,我收到的错误消息是

undefined method `columns' for Magick::ImageList

我有点不够深入,所以我不确定如何调试它,任何帮助将不胜感激,我整个周末都在努力解决这个问题。

4

2 回答 2

0

试试看Magick::ImageList.new(self.photo.to_file.path).path最后注意)。与其他图像相同。ImageList只接受文件名:

http://www.imagemagick.org/RMagick/doc/ilist.html#new

于 2010-12-04T01:31:12.997 回答
-1

如果您想接受图像上传(或仅存储图像)并调整它们的大小,我强烈建议您使用paperclip.

这是一个可以轻松安装的 gem。它与 S3 完美配合,可以一次性为您生成不同的缩略图。

查看https://rubygems.org/gems/paperclip了解更多详情。

于 2010-10-25T13:02:47.743 回答