Graphics Programming with Perl
Martien Verbruggen
  • May 2002
  • ISBN 9781930110021
  • 328 pages

Graphics Programming with Perl is a guide to the graphics and imaging modules and tools available to the Perl programmer. It covers subjects ranging from drawing your own pictures and dynamic graphics for web pages to rendering three-dimensional scenes and manipulating individual image pixels. The text is liberally illustrated with example code and programs that show how to achieve common, and sometimes not so common, graphics programming tasks. For the even less common tasks, the book shows you how to write your own modules.

Table of Contents detailed table of contents

preface

About this book

Who should read this book?

Coding practices

Source code downloads

author online

acknowledgments

about the cover illustration

Part 1 Foundations

1. Overview of graphics

1.1. Perl and graphics

1.2. The bits and pieces in graphics programming

1.3. Color spaces and palettes

1.3.1. RGB

1.3.2. CMY and CMYK

1.3.3. HSV and HLS

1.3.4. YUV, YIQ and YCbCr

1.3.5. Grayscale

1.3.6. Color distance

1.3.7. Reducing the number of colors in an image

1.4. Summary

2. Overview of graphics file formats

2.1. Some graphics formats

2.1.1. GIF

2.1.2. JPEG, JFIF

2.1.3. PNG

2.1.4. MNG

2.1.5. SVG

2.1.6. TIFF

2.2. Finding the size and type of an image

2.2.1. Image::Size

2.2.2. Image::Magick

2.2.3. Do it yourself

2.2.4. More on file size and information

2.3. Conversion of graphics formats

2.4. Summary

3. Overview of tools and modules

3.1. CPAN

3.2. The tools

3.2.1. The Chart::* modules

3.2.2. Gnuplot

3.2.3. GD

3.2.4. GD::Graph, GIFgraph and Chart::PNGgraph

3.2.5. GD::Text

3.2.6. The Gimp

3.2.7. Image::Magick

3.2.8. Image::Size

3.2.9. Inline

3.2.10. OpenGL

3.2.11. PGPLOT

3.2.12. RenderMan

3.2.13. Term::Gnuplot

3.3. A note on module versions

3.4. Summary

Part 2 Creating graphics

4. Drawing

4.1. Drawing with GD

4.1.1. An example drawing

4.1.2. Filling objects

4.1.3. Drawing text with GD

4.1.4. GD.s built-in fonts

4.1.5. TrueType fonts and GD

4.2. Drawing with Image::Magick

4.2.1. An example drawing

4.2.2. Anti-alias and fuzz

4.2.3. Drawing by combining images

4.2.4. Drawing with paths

4.2.5. Drawing text with Image::Magick

4.3. Combining GD and Image::Magick

4.4. Drawing with Term::Gnuplot

4.5. PostScript and SVG

4.6. Summary

5. Creating charts

5.1. GD::Graph and friends

5.1.1. Preparing your data sets for GD::Graph

5.1.2. Controlling the look of your chart

5.1.3. GD::Graph and fonts

5.1.4. Saving your chart to a file

5.1.5. Bar and area charts

5.1.6. Lines, Points and LinesPoints charts

5.1.7. Mixed charts

5.2. The Chart distribution

5.2.1. Pareto charts

5.3. PGPLOT

5.3.1. PGPLOT devices

5.3.2. Example: A simple X-Y plot

5.3.3. Example: A contour plot

5.3.4. Example: Plotting a galaxy

5.4. Interfacing with gnuplot

5.5. Summary

6. Graphics and the Web

6.1. The Common Gateway Interface

6.1.1. HTTP and CGI

6.2. Suitable image formats

6.2.1. Web safe color palettes

6.3. CGI and dynamically generated graphics

6.4. Forms and encapsulated graphics

6.5. Image collections and thumbnailing

6.5.1. Thumbnails with Image::Magick

6.5.2. Thumbnails with GD

6.5.3. Contact sheets with Image::Magick’s visual directory

6.5.4. Contact sheets with Image::Magick::Montage

6.5.5. An example application: A web photo album

6.5.6. Designing the data

6.6. Summary

7. Animations for the Web

7.1. Animation file formats

7.1.1. GIF

7.1.2. MNG

7.1.3. Macromedia Flash

7.1.4. SVG

7.2. GIF animations

7.3. Perl and animations

7.4. Repeatedly applying a filter

7.4.1. Example: making objects appear

7.4.2. Example: Zooming in on an object

7.5. Animated text

7.6. Animated charts

7.7. Animations with the Gimp

7.8. Summary

8. Resizing and combining images

8.1. Scaling and cropping an image

8.1.1. Image::Magick geometry specification

8.1.2. Cropping an image

8.2. Combining Images

8.2.1. Combining GD images

8.2.2. Combining Image::Magick images

8.2.3. Adding a watermark to an image

8.3. Summary

9. Three-dimensional graphics

9.1. OpenGL

9.1.1. OpenGL library functions in Perl

9.1.2. Capturing your OpenGL output

9.1.3. Example: a planetary system

9.1.4. OpenGL summary

9.2. RenderMan

9.2.1. How to use the module and the BMRT

9.2.2. The RenderMan language binding for Perl

9.2.3. Example: A rotating cube of cubes

9.3. Summary

Part 3 Special topics

10. Writing your own graphics modules

10.1. Interface design

10.1.1. Coordinate transformation

10.1.2. Choosing your drawing primitives

10.1.3. Implementing the interface

10.2. An OO implementation of a clock

10.3. Summary

11. Controlling text placement

11.1. Determining text size

11.1.1. Text sizes in GD

11.1.2. Text sizes in Image::Magick

11.2. Aligning text in graphics

11.2.1. Aligning text with GD

11.2.2. Aligning text with Image::Magick

11.3. Wrapping text

11.3.1. The GD::Text modules

11.4. Summary

12. Manipulating pixels and transparency

12.1. GD and pixels

12.1.1. Example: rotating RGB values

12.1.2. Removing duplicate color palette entries

12.2. Image::Magick and pixels

12.2.1. Rotating RGB values

12.3. Convolution

12.3.1. Convolution with Image::Magick

12.3.2. Using Image::Magick’s Convolve() method

12.3.3. Convolution with PDL

12.4. Alpha channels and transparency

12.4.1. Transparency and the GD module

12.4.2. Transparency and Image::Magick

12.4.3. How to view partially transparent images

12.5. Fast manipulation of image pixels

12.5.1. Using Inline::C

12.6. Summary

Part 4 Appendices

Appendix A: Image::Magick introduction & reference

Appendix B: Color space conversion algorithms

Appendix C: Module code

references

index

About the Technology

An increasing number of tasks in application programming and web design requires creating and manipulating graphics. Perl is a powerful and flexible language that is not commonly associated with graphics programming. The speed of developing in Perl plus the large number of freely available Perl graphics modules, make it an excellent option for the rapid development of graphics applications.

What's inside

  • How to create charts and graphs
  • Serving graphics content to the WWW with CGI
  • How to modularize your graphics code, and re-use it
  • Code to manipulate image pixels (and how to do it fast)
  • How to work with text in graphics
  • A complete reference for Image::Magick
  • Examples you can use and build on:
    • Adding watermarks to your images
    • Creating thumbnails
    • Dynamic web pages with charts
    • Building your own convolution filters
    • A web photo album
    • 3D animation with OpenGL and Renderman

About the author

A developer, architect and systems administrator, Martien Verbruggen is the author of the GD::Graph charting module and the GD::Text modules. He a regular contributor to the Perl Usenet groups. Martien lives in Sydney, Australia with his wife and daughter.


combo $39.95 pBook + PDF
eBook $31.99 PDF only

FREE domestic shipping on three or more pBooks