Hundreds of standards exist for storing structured data in text or binary files. Some of these are so popular that we've devoted entire chapters to them (Chapters 11 and 13). Some are so simple that you can process them with the ad hoc techniques listed in Chapters 1 and 6. This chapter is a grab bag that tries to cover the rest of the field.
We focus especially on graphics, probably the most common binary files. Ruby lacks a mature image manipulation library like the Python Imaging Library, but it does have bindings to ImageMagick and GraphicsMagick, popular and stable C libraries. The RMagick library provides the same interface against ImageMagick and GraphicsMagick, so it doesn't matter which one you use.
You can get RMagick by installing the
Rmagick-win32 gem. Unfortunately, the C
libraries themselves are difficult to install: they have a lot of
dependencies, especially if you want to process image formats like GIF and
PostScript. The installation FAQ can help (http://rmagick.rubyforge.org/install-faq.html). On Debian
GNU/Linux, you can just install the
imagemagick package and then the
The first recipes in this chapter show how to use RMagick to manipulate and convert images (on the question of finding images, see Recipe 16.2). Then it gets miscellaneous: we cover encryption, archive formats, Excel spreadsheets, and music files. We don't have space to cover every popular file format, but this chapter should ...