<<

Perl Programming

Shawn Wallace

O'REILLY8 Beijing • Cambridge • Farnham • Koln • Paris • Sebastopol • Taipei • Tokyo

Preface ix

Part I. Raster Images and Web Graphics

1. Creating Graphics with Perl 3 tq File Formats 3 Color 5 Raster File Formats 10 Vector Graphic File Formats 17 Document File Formats 21 References 24

2. On-the-Fly Graphics with GD 25 GD Basics 26 Sample GD Applications 27 Reading and Writing Methods 35 Getting and Setting General Information 40 Color Table Manipulation Methods 41 Brushes, Styles, and Tiles 44 Copying and Transforming Images 48 Image Drawing and Manipulation Methods 50 Strings and 53 Polygon Methods 55

3. Graphics Scripting with lmage::Magick 62 What Is ImageMagick? 62 Using Image ::Magick 65 Sample Image: :Magick Applications 70 Reading and Writing Images 79 Retrieving and Setting File Information 82 Sizing and Transforming Images 86 Copying and Composing Tfriages 91 Color and Transparency 95 Annotation and Drawing 100 Filters and Effects 106

4. ChartsandGraphswithGD::Graph 117 Let's Make Some Graphs! 117 A Sample GD::Graph Application 125 GD::Graph Methods 130 Attributes of GD::Graph Objects 134 Colors and Fonts in GD::Graph 142

5. Scripting the Gimp with Perl 145 Getting and Installing the Gimp 145 Writing Gimp Plug-ins in Perl 148 Your First Gimp Script 150 Object-Oriented Versus Procedural Scripting 155 Adding New Features to the Gimp 158 Standalone Scripts 171

Part II. Vector Images and Animations

6. SVG: The Scalable Format 175 SVG Document Structure 176 The Basic SVG Tags 180

7. Creating SVG with Perl 195 A Slide-Show Presentation 195 SVG Animation 201 Creating a Bouncing Ball 202 SVG Scripting with JavaScript 204 Using Unicode Text in SVG Images 208 Transformation with XSLT and Perl 210

Table of Contents 8. SWF: The Flash 215 The History of Flash and SWF 215 The Format and Function of SWF Files 216 Anatomy of'a Tag 223 Parsing an SWF File with Perl 233

9. Using Ming 238 Installation 238 Overview of the Perl Interface 239 The Astral Trespassers Game 240 The SWF Module 246 The SWF::Movie Module 247 The SWF::Sprite (or SWF::MovieClip) Module 249 The SWF::DisplayItem Module 250 The SWF::Shape Module 254 The SWF: :Button Module 259 The SWF: :Bitmap Module 262 The SWF: :Text Module 263 The SWF::TextField Module 265 The SWF .-. Module 267 The SWF::Fill Module 268 The SWF::Gradient Module 269 The SWF::Morph Module 269 The SWF: :Sound Module 272 The SWF::Action Module 272 SWF Recipes 273

Part III. Documents and Printing

10. Printing with Postscript and PDF 291 PostScript in a Nutshell 291 Portable Document Format (PDF) 299 References 314

11. Using the PostScript Modules 315 Creating PostScript from a Web Interface 316 The PostScript: :TextBlock Module 320 The PostScript::Document Module 326

Table of Contents I vii The PostScript::Elements Module 328 Other PostScript Modules 332

12. Creating PDF Documents with Perl 333 Introduction to PDF::API2 333 Creating Address Labels 336 Adding to Existing PDF Files 341 PDF::API2 Reference 343 PDF::API2::Page 347 PDF::API2::Content 349 PDF::API2::Gfx 353 PDF::API2::Text 355 PDF::API2::Outline 357 References 360

Part IV. Appendixes

A. Serving Graphics on the Web 363

B. Gimp Reference 385

C. lmage::Magick File Formats 413

D. ActionScript Reference 418

Index 437

viii I Table of Contents