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?
You will have to write the image to a file and view it with a separate image viewer. 2If you installed RMagick using Rubygemsyou must set up the RubyGems environment before using RMagick. You can do one of add the require 'rubygems'statement to your program use the -rubygems command line option
(Click the image to see the Ruby program that created it.) RMagick's primitive methods include methods for drawing points, lines, Bezier curves, shapes such as ellipses and rectangles, and text. Shapes and lines have a fill color and a stroke color.
2If you installed RMagick using Rubygemsyou must set up the RubyGems environment before using RMagick. You can do one of add the require 'rubygems'statement to your program use the -rubygems command line option add rubygemsto the RUBYOPT environment variable See the RubyGems docfor more information.
ImageMagick supports a set of 2D drawing commands that are very similar to the commands and elements defined by the W3C's Scalable Vector Graphics (SVG) 1.1 Specification. In RMagick, each command (called a primitive) is implemented as a method in the Drawclass. To draw on an image, simply Create an instance of the Drawclass.
This should work:
image[0].write(path)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With