2013-07-02 50 views
6

Rmagick指南:rmagick有没有办法转换图像在内存

将图像转换为另一种格式

将图像转换为另一种格式是作为 图像写入文件一样简单。

ImageMagick使用输出文件名称suffix (".jpg" for JPEG, ".gif" for GIF, for example)prefix ("ps:" for PostScript, for example)来确定输出图像的格式。

有没有办法在内存中转换图像?

+0

在使用图像中一些可能的“难懂的”格式之一举行,转换的概念这不是那么明确。您是否基本上想避免将内容写入磁盘,以便HTTP可以从内存中提供特定的图像类型? –

+0

是的,我想避免写入磁盘。 –

回答

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

来源:RMagick Docs

这里有一个例子如何give it to the user

image.format = "png" 
send_data image.to_blob, 
    :filename => "woohoo.png", 
    :disposition => 'inline', 
    :quality => 90, 
    :type => 'image/png' 
相关问题