从 rmagick 图像创建回形针附件
我无法找到一种方法将使用 RMagick 创建的图像保存在回形针附件中。
imageList = Magick::ImageList.new
imageList.new("images/apple.gif", "images/overlay.png")
...
picture = imageList.flatten_images
我所在的模型有一个附加文件
has_attached_file :图片, :网址=> ..., :路径=> ...
我只想将 imageList.flatten_images 返回的图像保存为模型的图片。
请问有人知道如何轻松做到吗?
谢谢
I have a problem to find a way to save an image created with RMagick in a paperclip attachment.
imageList = Magick::ImageList.new
imageList.new("images/apple.gif", "images/overlay.png")
...
picture = imageList.flatten_images
I am in a model that have an attached file
has_attached_file :picture,
:url => ...,
:path => ...
and i just want my image returned by imageList.flatten_images to be saved as the picture of my model.
Does anyone know how to do it easily please?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
让我们看看这是否是您所需要的
将
YourModel
更改为您正在使用的模型...Let's see if that's what you need
Change
YourModel
with the model you are using...您应该在 TempFile.new 上强制扩展;在这种情况下,我从 S3 或类似的东西中提取原始图像,这当然发生在模型中:
You should force the extension on TempFile.new; in this case I pull the original image from S3 or some such, this is happening in the model of course:
在 Paperclip 的更高版本中(我的是
5.0.0
),您需要提供 Paperclip 自己的Tempfile
实例:这会保留文件名末尾的文件扩展名,以便回形针在上传时能够识别它。
In the later versions of Paperclip (mine is
5.0.0
), you'll need to provide Paperclip's ownTempfile
instance:This preserves the file extension at the end of the filename, so that it is recognized by Paperclip when it's uploaded.