O'Reilly logo

Ruby Cookbook, 2nd Edition by Leonard Richardson, Lucas Carlson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 13. Graphics and Other File Formats

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 12 and 14). Some are so simple that you can process them with the ad hoc techniques listed in Chapters 2 and 7. 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 or 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. On Debian GNU/Linux, you can just install the imagemagick package and then the RMagick gem.

The first recipes in this chapter show how to use RMagick to manipulate and convert images (on the question of finding images, see Recipe 18.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 give you an idea of what’s out there. If this chapter lacks a recipe on your ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required