Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rmagick is there a way to convert image in memory

From Rmagick guide:

Converting an image to another format

Converting an image to another format is as simple as writing the image to a file.

ImageMagick uses the output filename suffix (".jpg" for JPEG, ".gif" for GIF, for example) or prefix ("ps:" for PostScript, for example) to determine the format of the output image.

Is there a way to convert image in memory?

like image 450
Lesha Pipiev Avatar asked Jul 02 '13 11:07

Lesha Pipiev


1 Answers

# assuming you have an image
# img = Magick::Image.new( 100, 100 )
img = Magick::Image.from_blob( img.to_blob { self.format = "png" } )

Source: RMagick Docs

Here's an example on how to give it to the user

image.format = "png"
send_data image.to_blob,
    :filename => "woohoo.png",
    :disposition => 'inline',
    :quality => 90,
    :type => 'image/png'
like image 96
Dan Grahn Avatar answered Oct 27 '22 01:10

Dan Grahn