回形针将原始图像存储在" original“文件夹中。有没有办法调整原始图像的大小?为了节省磁盘空间,我想把原件做小一点。
例如,如果访问者上传了一张2592x1936的照片,我希望将其存储为1024x1024,就像我们在:styles中设置:thumb图像的尺寸一样
更新(已解决)
我发现了如何在上传时自动调整原始图像的大小。只需将:original添加到样式中:
class MyModel < ActiveRecord::Base
has_attached_file :photo,
:styles => { :original => "1024x1024>", :thumb => "150x150>" }
end
发布于 2011-08-11 22:33:12
我不确定回形针是否能自动调整大小。您可能需要查看Rmagick才能完成此任务。我会尝试运行RMagick (或minimagick),然后使用before_save回调来执行您编写的:resize
方法,该方法告诉RMagic调整图像的大小。您的方法可能如下所示:
class Image < ActiveRecord::Base
belongs_to :profile
before_save :resize
def resize
self.image = self.image.resize "1024x1024"
end
end
或
class Image < ActiveRecord::Base
belongs_to :profile
before_save do
self.image = self.image.resize "1024x1024"
end
end
https://stackoverflow.com/questions/7027335
复制相似问题