Science releases MojoMagick, an Ruby language image library “that does very little” ™. There are several useful image tools that “do a lot” - MojoMagick is designed to just a few things:
- Be fast
- Don’t leak memory
- Make simple ImageMagick tasks, simple as Ruby tasks
- Permit direct access to ImageMagick for complex tasks (i.e. get out of your way)
- Provide a central access to ImageMagick for good code architecture
- Easy to extend
- Limit memory accessible to ImageMagick (where desired)
That’s what it does. It’s packaged as a Rails plugin, but does not require Rails to run. If there’s any interest, I’ll make it a gem (just ask).
You can download a copy by following the instructions here.
Looks very interesting. How does it differ from Rmagick/minimagick ?
A gem would be a very good idea
RMagick hooks ImageMagick via DLL’s (last I looked). As a result it leaks memory like a sieve (last I looked). It’s fine for Ruby processes where the interpreter spins up, runs your code, and exits back to the OS. But it’s pretty bad in Rails, where the the interpreter spins up, and is re-entrant into the Rails stack over and over.
Minimagick is very similar to MojoMagick in that they both use shell execution to accomplish their work. As a result, they don’t leak memory like RMagick. However, I have personal, anecdotal experience with Minimagick also leaking memory. I can’t say for sure, but that’s my unscientific experience.
Most importantly, MiniMagick uses temp files to manipulate images. So if you want to get the size of an image in MiniMagick, the framework will copy your image to a temp file, and get the size of the temp file. If you want to resize an image in place, it will copy to a temp file, resize and copy back to the original. MojoMagick permits you to operate on a file directly and its built in functions (like resize and “get dimensions”) do this automatically for you.
Significantly, MojoMagick supports easily limiting memory usage in ImageMagick. IM can use a surprising amount of memory and if you are in a limited RAM environment it can cause your core application to swap to disk which is Not Good.
To limit memory usage in MojoMagick, be sure you’re upgraded to the current release of ImageMagick. Then you can use this code to examine and limit various ram components:
I’ll get to work on a gem soon!
Version 0.0.2 released: improved resource limits, error trapping
This is fantastic… saves me the hassle of hacking up minimagick to convince it to pass a command line.