【发布时间】:2017-01-09 19:36:37
【问题描述】:
在我的 Rails 应用程序中,我有一个模块可以拍摄多张图像,然后使用 RMagick 将它们“缝合”在一起,形成一个新的单一图像。我能够成功创建最终图像,但我无法将此新图像保存为模型的附件(使用 CarrierWave)。拼接的方法如下:
def generate_collage(params)
final_image = ImageList.new
# ... code that puts together the composite image ...
return final_image.append(true).to_blob { |attrs| attrs.format = 'JPEG' }
end
我的用户模型安装了上传器:
class User < ActiveRecord::Base
mount_uploader :image, UserImageUploader
end
在the ActiveRecord section 下的 CarrierWave 文档中,他们展示了如何分配新图像,但他们假设文件已经存在于某处。在我的情况下,它在文件系统上尚不存在,我正在输出 blob...有没有办法从该 blob 生成 CarrierWave 的图像上传?
我想我想避免将此图像暂时保存到 "#{Rails.root}/tmp/" 然后从那里读取它...似乎我可以删掉这一步并以某种方式直接发送到 CarrierWave,但我不知道如何!可能吗?
【问题讨论】:
标签: ruby-on-rails ruby image-processing carrierwave image-uploading