Archive for ‘C’

October 14, 2009

The DevIL Image Library For Ruby

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.

Example Code:

Devil.with_image("horse.png") do |img|

Note that the Ruby Devil implementation also supports the traditional DevIL API for greater control (though extra fiddliness):


name = IL.GenImages(1)[0]


ILU.Scale(100, 100, 1)



Ubuntu/Debian systems:

  • aptitude install libdevil1c2 libdevil-dev

Gentoo systems:

  • emerge “media-libs/devil”

Macosx systems:

  • sudo port install libdevil

Windows systems:

For other systems:

Installing The Gem:

After setting up the DevIL library (as described above) you need to install the Ruby Devil gem:

  • gem install devil

Gosu Compatibility:

If you wish to use Devil with the Gosu game development library you will also need the following gems:

  • Gosu (gem install gosu)
  • TexPlay (gem install texplay)
  • ruby-opengl (gem install ruby-opengl)

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:


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.

Project Page:

The github project can be found here:

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.