Writing image data to a file in ruby ​​using rmagick

I want to write an image to a file using rmagick. 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 also tried using f.write(image) . But what is written in the file is #<Magick::Image:0x7eff0587f838> . What is the reason for this?

+6
source share
1 answer

This should work:

 image[0].write(path) 
+3
source

All Articles