回形针将原始图像存储在“original”文件夹中。有没有办法调整原始图像的大小?我想缩小原件以节省光盘空间。
因此,例如,如果访问者上传一张 2592x1936 的照片,我想将其存储为 1024x1024,就像我们在 :styles 中设置 :thumb 图像的尺寸一样
更新(已解决)
我发现了如何在上传时自动调整原始图像的大小。只需要添加一个:原来的样式:
class MyModel < ActiveRecord::Base
has_attached_file :photo,
:styles => { :original => "1024x1024>", :thumb => "150x150>" }
end
我不确定回形针是否会自行调整大小。您可能需要查看 Rmagick 才能完成此任务。我会尝试让 RMagick 继续运行(或者迷你魔术 https://github.com/probablycorey/mini_magick),然后使用 before_save 回调执行:resize
您编写的告诉 RMagic 调整图像大小的方法。您的方法可能如下所示:
class Image < ActiveRecord::Base
belongs_to :profile
before_save :resize
def resize
self.image = self.image.resize "1024x1024"
end
end
or
class Image < ActiveRecord::Base
belongs_to :profile
before_save do
self.image = self.image.resize "1024x1024"
end
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)