DevIL is a fast and lightweight image library that supports the loading and saving of images in almost any format. It also provides some basic image manipulation functionality.
- Loading and saving of images.
- Thumbnailing and scaling.
- Rotations, cropping, composites, gamma correction, image sharpening, blurring, etc.
- Interoperability with the Gosu game development framework.
Devil.with_image("horse.png") do |img| img.thumbnail2(150) img.gamma_correct(1.6) img.rotate(45) img.save("horse_thumb45.jpg") end
Note that the Ruby Devil implementation also supports the traditional DevIL API for greater control (though extra fiddliness):
IL.Init name = IL.GenImages(1) IL.BindImage(name) IL.LoadImage("horse.png") ILU.ImageParameter(ILU::FILTER, ILU::SCALE_BSPLINE) ILU.Scale(100, 100, 1) IL.Enable(IL::FILE_OVERWRITE) IL.SaveImage("horse_scale.png")
- aptitude install libdevil1c2 libdevil-dev
- emerge “media-libs/devil”
- sudo port install libdevil
- download devil-dlls.zip from http://github.com/banister/devil/downloads
- and copy the uncompressed files to c:\ruby\bin\
For other systems:
- locate and install libdevil and libdevil-dev using your package manager
- OR download and compile the sourcecode from http://openil.sourceforge.net
Installing The Gem:
After setting up the DevIL library (as described above) you need to install the Ruby Devil gem:
- gem install devil
If you wish to use Devil with the Gosu game development library you will also need the following gems:
Devil augments the Gosu library in a few ways. It lets you load image files in multiple formats (Gosu itself is restricted to png and bmp). It lets you *save* Gosu::Image objects to files (only useful if the images have first been manipulated using TexPlay). Devil also provides a ‘screenshot’ method to the Gosu::Window object enabling you to take screenshots of your gameplay and save it to a file.
Note that if you combine the use of Devil with TexPlay you get a fairly complete image manipulation framework. TexPlay enhances the basic functionality of Devil, providing the ability to draw lines, circles, rectangles, bezier curves, polygons, composites, turtle graphics, l-systems and more. See TexPlay for more information.
Reasonably comprehensive documentation for the high-level Devil wrapper (not the low-level API) can be found here: http://rdoc.info/projects/banister/devil
This Ruby Devil gem is heavily based on the ruby-devil project started by Jaroslaw Tworek but abandoned in 2006.
Some elements of the Devil API are based on the image_science project by seattlerb.
The github project can be found here: http://github.com/banister/devil
If you have any problems please file an issue on that page. Devil is a relatively new project and there may be some minor (or even major🙂 ) bugs still present.