Chapter 15. Graphics

Introduction

Most web pages, however fancy and clever, are essentially composed of text and images. Dynamic web applications do some sort of processing to produce some of their text on-the-fly. It makes sense that some of your applications will need to be able to produce and process images as well. Luckily for Rails developers, there is a growing number of great tools for handling visual output.

For example, the Swiss Army chain-saw of image processing, ImageMagick, is available to Ruby in the form of the RMagick gem. This chapter will show you how to install and use RMagick, giving your Rails applications the ability to manipulate images and produce interesting graphical output.

We’ll also look at techniques for uploading, storing, and displaying images using a database, as well as those for generating PDF files from a variety of source data.

Finally, we’ll examine a couple of tools for visualizing and graphing data with Rails: Gruff and Sparklines.

These are only a small sampling of the rapidly growing number of tools that are available to add some dynamic visual impact to your web sites.

Installing RMagick for Image Processing

Problem

Contributed by: Matt Ridenour

You would like your Rails application to create and modify graphic files, performing tasks such as generating thumbnail previews, drawing simple graphs, or adding textual information such as a timestamp to an image.

Solution

RMagick is an interface that gives Ruby access to the ImageMagick or GraphicsMagick ...

Get Rails Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.