Preface

Welcome to Programming Web Graphics with Perl and GNU Software ! In this book we will focus on two areas: generating web graphics “on the fly,” and creating web graphics using a scripting language (Perl) to simplify mundane or repetitive tasks. Intermediate and advanced web users will probably get the most out of this book, though hopefully it will demystify the manipulation of graphics files for newcomers as well.

Programming Web Graphics takes a practical approach to the material. It is not a book about the design or aesthetics of web graphics; its focus is on writing programs that manipulate graphics files to be published on the Web. The examples in the book use Perl as a scripting language, although the concepts are applicable to any programming language. Perl is well-suited for web graphics programs for several reasons:

  • Perl is ubiquitous on the Web.

  • Perl has many free, reusable modules for generating web graphics, such as the GD and GIFgraph modules described in Chapter 4 and Chapter 6.

  • Perl has interfaces to more powerful image manipulation tools, such as ImageMagick (Chapter 5) and the Gimp (Chapter 7).

  • Perl has a bevy of well-developed modules for various web applications that support the cause of programming web graphics. The popular CGI module (Chapter 2) allows you to easily create CGI scripts, for instance.

  • Perl is easily integrated with high-performance web servers. The mod_perl extension to the Apache web server, for example, offers a significant performance improvement over other implementations.

  • Perl is a fast, well-documented, and popular scripting language.

Most of the topics in this book are applicable to any platform (NT, Linux, Unix, even MacOS), with the exception of the chapter detailing the Gimp (Chapter 7), which (for now) exists primarily on Linux and Unix systems. The focus is always on free software, when it is available.

Contents of This Book

The book is divided into three parts. Part I, provides a survey of the current state of web graphics:

Chapter 1

In which the “black box” of the three predominant web graphics formats (GIF, JPEG, and PNG) is opened, explored, and accompanied by a discussion of web graphics concepts such as transparency, compression, interlacing and color tables. Chapter 1 is supplemented by Appendix A, which details a simple implementation of a PNG decoder script written in Perl.

Chapter 2

In which we present the standard ins and outs of creating CGI scripts that generate dynamic images, and take a look at the HTML tags that embed images in web pages.

Chapter 3

In which we briefly tour some of the more useful free graphics libraries available on the Web. The average end user will probably not use these resources directly, but a number of them (the Independent JPEG Group’s libjpeg and the PNG libraries, for example) are used by most web browsers to implement graphics support, so it is good to know about them.

Part II, is dedicated to documenting several tools for generating web graphics:

Chapter 4

In which we discover the GD module and explore its use in CGI applications. The GD module is a collection of functions for reading, manipulating, and writing color GIF files. GD is great for quick and dirty scripts that are fast and not all that dirty, but it is limited in that it can only read and write GIF files.

Chapter 5

In which we are introduced to ImageMagick and its Perl interface. ImageMagick is a collection of functions and a transparent interface for reading and writing over forty different graphics file formats. It is a great “Swiss army knife” for image conversions, scaling, cropping, and color management. It can handle file formats that contain multiple images in a single file, such as GIF89a. ImageMagick is (of necessity) a bit bulky, however, and may not be suited for all CGI programming tasks, though it certainly can be used for a lot of them.

Chapter 6

In which we use GIFgraph to create graphs from data provided by an HTML form. GIFgraph is a Perl module that extends the GD module by offering a number of functions for creating many types of graphs and charts. For quite a while, almost all of the financial graphs or web server load graphs that you would find on the Web were generated by CGI scripts using GIFgraph to generate the images.

Chapter 7

In which we learn how to use the Gimp-Perl module to create custom plug-ins for the GNU Image Manipulation Program. The Gimp started out as a free “Photoshop-like” program. It would be inaccurate to call the current version of the Gimp a Photoshop clone, however, as the Gimp has surpassed Photoshop in certain areas, and has marked out new territories for image manipulation. The Gimp has a sophisticated scripting interface (several, actually). In this chapter we use the Gimp-Perl interface to write Gimp plug-ins. Chapter 7 is supplemented by Appendix B, which provides a reference guide for the Gimp, and Appendix C, which provides a reference to the procedures available to Gimp-Perl scripts.

Part III, focuses on specific web-based graphics applications:

Chapter 8

In which we discuss client-side (and server-side) image maps and create an example script that generates image map regions on the fly from data retrieved from a database.

Chapter 9

In which we are presented with seven easy GIF animation scripts using ImageMagick, and are introduced to a home-brewed language called GIFscript that describes the structure of animated GIF files.

Chapter 10

In which we are presented with a number of common web graphics recipes, with reusable code examples written in Perl.

Chapter 11

In which we are introduced to the PostScript page description language, and develop a framework for easily generating PostScript code to leap the separation between the Web and the printed page.

Part IV, supplements Chapter 1 and Chapter 7.

Get Programming Web Graphics with Perl and GNU Softwar 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.