使用rmagick将图像数据写入ruby中的文件

nnm*_*nnm 6 ruby ruby-on-rails rmagick image-processing

我想使用rmagick将图像写入文件.以下是我的代码

im = "base64encodedstring"
image = Magick::Image.from_blob(Base64.decode64(im)
image[0].format = "jpeg"
name ="something_temp"
path = "/somepath/" + name
File.open(path, "wb") { |f|
    f.write(image[0])
}
Run Code Online (Sandbox Code Playgroud)

我也试过用f.write(image).但是在文件中写的是#<Magick::Image:0x7eff0587f838>.这是什么原因?

Mar*_*pka 4

这应该有效:

image[0].write(path)
Run Code Online (Sandbox Code Playgroud)