Rmagick How to Convert Image in Memory

rmagick is there a way to convert image in memory

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

Converting SVG to PNG with RMagick in memory

The RMagick doc for from_blob says that from_blob returns an array of images, so my guess is that this should work:

arr = Magick::Image.from_blob(str)
str = arr[0].to_blob

RMagick - convert file to another format without saving to disk

You can specify the format when calling to_blob. From the fine manual:

to_blob img.to_blob [ { optional arguments } ]-> string

[...]

No required arguments, however you can specify the image format (such as JPEG, PNG, etc.) and depth by calling the format and depth attributes, as well as other Image::Info attributes as appropriate, in a block associated with the method.

So you can say things like this:

png_bytes = img.to_blob { |attrs| attrs.format = 'PNG' }

Yes, the interface to to_blob is a bit odd but the strange interface is just part of the fun of working with ImageMagick.

You can also use the format= method before calling to_blob:

img.format = 'PNG'
png_bytes = img.to_blob

Generate animated rotating image and displaying in memory version using rmagick and Sinatra

I found a solution - not sure if it's optimal at all but it works. I hope someone out there has a better answer than me :)

I forced the img I passed into self.spin to be a gif, and that made it so the image animated. Here's what my self.spin method looks like now:

def self.spin(img)
spinny_image = Magick::ImageList.new
img.format = "gif"

spinny_image << img
spinny_image << img.rotate(90)
spinny_image << img.rotate(180)
spinny_image << img.rotate(270)

spinny_image
end

RMagick - Correct way to create a thumbnail without leaking memory

Try minimagic, which was written to deal with exactly the problem you're having.

For most tasks, the minimagic gem linked here is sufficient. It runs ImageMagick's command-line tools, which means a new process is created, it runs, and then stops, freeing memory. We replaced RMagic with MiniMagic and our memory woes were a thing of the past.

Rails rmagick - Converted Image Turns Solid Black When 'resize_to_fit' applied

It's possible your PDF file has a transparent background, which is causing the problem. Try removing the alpha channel before the resize using

pdf.first.alpha(Magick::DeactivateAlphaChannel)
pdf.first.resize_to_fit!("600")

RMagick with a direct form submitted Image from Sinatra

You need to get the path from the tempfile and pass that to Magick::Image’s read.

Here’s an example:

post "/upload-photo" do
image = Magick::Image.read(params[:image][:tempfile].path)[0]
image.crop_resized! 100, 100, Magick::CenterGravity
store_image_data image.to_blob

redirect "/done"
end

Use convert method of imagemagick in ruby on rails application

This guy looks like answer your question: https://stackoverflow.com/a/17426622/159995.

Or you can just use system('convert /home/icicle/Desktop/images_284.tif /home/icicle/Desktop/images_284.jpg')



Related Topics



Leave a reply



Submit