Rails - 如何即时生成缩略图
我正在寻找一种方法来动态生成上传图像的缩略图。我有一个看起来像这样的产品模型:
class Product
include Mongoid::Document
include Mongoid::Paperclip
has_mongoid_attached_file :picture
end
我基本上只想上传一张高分辨率图片,然后我可以将其用于缩略图、主图像以及精美盒子的高分辨率图片等。
是有一个简单的方法可以做到这一点吗?
I am looking for a way to generate thumbnails of my uploaded images on the fly. I have a product model that looks kind of like this:
class Product
include Mongoid::Document
include Mongoid::Paperclip
has_mongoid_attached_file :picture
end
I basically just want to upload one high-res picture, which I can then use for thumbnails, the main image and also the high-res picture for fancy-box etc..
Is there an easy way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为回形针 Attached_file 设置许多属性。
例如,
您可以为多个版本的图像设置 :styles 属性,并具有您想要的尺寸和格式。
请查看此处了解更多详细信息。不过,您确实需要像 RMagick / Imagemagick 这样的图像处理器。
There are many attributes you can set for paperclip attached_file.
e.g.,
You can set the :styles attributes with many versions of the image with the sizes and formats you want.
Check here for more details. You do need image processor like RMagick / Imagemagick though.