nnm
nnm

Reputation: 1425

writing image data to file in ruby using rmagick

I want to write image to a file using rmagick. Given below is my code

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])
}

I have also tried to use f.write(image). But what get written in the file is #<Magick::Image:0x7eff0587f838>. What is the reason for this?

Upvotes: 6

Views: 6747

Answers (1)

Marek Lipka
Marek Lipka

Reputation: 51151

This should work:

image[0].write(path)

Upvotes: 4

Related Questions