本文介绍了从 rmagick 图像创建回形针附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在想办法将使用 RMagick 创建的图像保存在回形针附件中时遇到了问题.
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:图片,:url =>...,:路径=>...
我只想将 imageList.flatten_images 返回的图像保存为我的模型图片.
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?
谢谢
推荐答案
让我们看看这是否是您所需要的
Let's see if that's what you need
picture = imageList.flatten_images
file = Tempfile.new('my_picture.jpg')
picture.write(file.path)
YourModel.create(:picture => file, ...)
使用您正在使用的模型更改 YourModel
...
Change YourModel
with the model you are using...
这篇关于从 rmagick 图像创建回形针附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!