Skip to content

Instantly share code, notes, and snippets.

@abhas
Created December 12, 2011 11:08
Show Gist options
  • Save abhas/1466632 to your computer and use it in GitHub Desktop.
Save abhas/1466632 to your computer and use it in GitHub Desktop.
Using Rmagick to process images from buffers instead of file paths

Most documentation for Rmagick that I found shows you how to read images into an Rmagick object from a file path. However, I have a situation where I had a file stored in a MongoDB database and needed to process it with Rmagick.

The from_blob method did this for me. In a single line, I was able to read the file from the database into a buffer and pass that directly to Rmagick! :)

img = Magick::Image::from_blob(@document.file.read)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment