rmagick is there a way to convert image in memory

前端 未结 1 1384
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-18 02:39

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.

1条回答
  •  有刺的猬
    2021-01-18 03:23

    # 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'
    

    0 讨论(0)
提交回复
热议问题