From Rmagick
guide:
来自Rmagick指南:
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.
ImageMagick使用输出文件名后缀(例如,JPEG为“.jpg”,GIF为“.gif”)或前缀(例如,对于PostScript为“ps:”),以确定输出图像的格式。
Is there a way to convert image in memory?
有没有办法在内存中转换图像?
1 个解决方案
#1
7
# 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
资料来源: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'
#1
7
# 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
资料来源: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'