Geared toward Perl users and webmasters, Perl Graphics Programming and PDF--then you'll explore the most powerful tools and Perl modules available for. Perl Graphics Programming. Shawn Wallace Part I. Raster Images and Web Graphics. 1. Creating Creating PDF Documents with Perl. Perl. Graphics. Programming. Shawn Wallace. Creating SVG, SWF (Flash), JPEG , and PNG The Perl interface consists of 14 modules in the SWF namespace.
|Language:||English, Spanish, Dutch|
|Genre:||Business & Career|
|PDF File Size:||11.68 MB|
|Distribution:||Free* [*Regsitration Required]|
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. Graphics Programming with Perl - Manning pdf - Ebook download as PDF File .pdf), Text File .txt) or read book online. How to Write a Better Thesis What Is a Thesis? David Evans†, Paul Gruba, Justin Zobel · Download PDF Chapter. Page.
After a few unsatisfactory tries with Klamuka and Klamuk.
Following the links. R This work is very useful especially for those who hold themselves to be universal travelers Although nothing is known of the designers. Obra muy util y en special para los que tienen la del viajero universal which we translate.
Coleccion general de los Trages que usan actualmente todas las Nacionas del Mundo desubierto. This was a time when the dress codes of two regions separated by a few dozen miles identified people uniquely as belonging to one or the other. General collection of costumes currently used in the nations of the known world. We at Manning celebrate the inventiveness. Chapter 1 discusses concepts in graphics programming in general terms and places them in a Perl context.
Chapter 2 contains information on the various storage formats for graphics. It is not an exhaustive discussion of everything there is to know about Perl and graphics programming in general. P A R T 1 Foundations P art 1 contains a basic discussion of the foundations on which rest the other chapters in this book. Charts and graphs are created to visualize everything ranging from business throughput.
Because computers have become more powerful. Just think of all the images out there that are resized. This in turn has increased the expectancy that your application creates graphical output—either interactively.
There are more and more photos and stills from videos to manipulate. Even without the Web the amount of image processing would have grown. Apart from increasing the amount of graphics needed as buttons and embellishments for web sites. The advent of digital cameras and affordable frame capture hardware have also contributed to the increase in graphics manipulation.
Together with the outpouring of images processed. In this chapter we will have a look at the various elements of graphics programming that are important to programmers. Which library you decide to use depends. This proliferation of tools can make it difficult to pick the right one for the job at hand. There are. Even when you do write your own tools. Then there are the images that are created on the fly as the result of user input. And this is why Perl can be very useful for graphics programming.
Other packages have been written that make use of these modules to create graphics at a higher level. So why does this book exist? Perl is a glue language. No one of course knows the exact numbers. Not all graphics tasks lend themselves to automation. Programs that manipulate or create graphics are in many ways similar to programs for other tasks. Sometimes there is no tool available that will satisfy all the requirements of the task. Writing code for graphics manipulation can be quite time-consuming.
Apart from the reasons just mentioned. It can also be used to write large software projects. In cases where the need is to jump down to a low level and do some computationally intensive programming. Perl is duct tape. The demands on programs that manipulate computer graphics will probably flatten out at some point. All the number crunching. This does not mean that you cannot. Of course. At the same time.
Even if you generalize that to all computing. Perl is also an attractive language with which to program. As a side note to the number crunching: Chapter 12 gives a few examples of how to do this in pure Perl.
Most of these modules were. The same chapter also explains how to write parts of your program in C. Perl can be used as a tool to quickly hack together a program that parses sets of log files. Perl provides access to lower-level languages without too much fuss.
The fourth element consists of the tools used for drawing. This indicates where on the canvas an object is located or an operation takes place. A second element common to all graphics operations is a frame of reference expressed in coordinates. It is important to note that a canvas can be part of another canvas. Sometimes people consider the manipulation of single pixels in an image to be a separate class of actions. While the primitives of most graphics programming fall into one of the groups mentioned above.
Figure 1. When you want to resize a set of images. Something that is the canvas for one operation might be the brush or object to be drawn for another. Most commonly these coordinates are Cartesian. Many graphics packages or graphics operations function at a higher level than described earlier. In PostScript. These can be a brush. First of all there is the canvas.
And in fact.. These are normally found on icon bars in interactive drawing programs. The whole graphic for one operation could be just a layer or a drawing object for another. Most of the time these objects will have one or more handles. A pixel is simpler and has fewer parameters.
These colors are called primary colors. As children we were taught that red. Some others are filters that work directly on the contents of an object.
Apart from these considerations.
Some of these operations are stretching. All colors we see can be expressed as a composition of at least three other colors. The main reason that this color space is used is due to the fact that computer monitors perform their function with phosphorizing agents that emit those three colors. When you use one of the modules that creates a chart you are hardly interested in which low-level graphics operations it must execute to produce the picture.
More on the manipulation of images as a whole. It turns out that it is possible to come up with several other useful color spaces.
The human eye is capable of distinguishing large numbers of colors. There are also operations that let you combine graphical objects in various manners. In addition to the creation and handling of these drawing primitives. The coordinates into that space are the relative amounts of each primary color. Chapter 10 contains more discussion on coordinate systems and frames of reference.
This is because we use three different types of sensors on our retina to perceive color. This section provides a short overview of the color models most frequently used.
These three primaries are the opposites. For the RGB color space this cube can be seen in figure 1. This means that visually. In other words. The gray colors are in exactly the same position.
In practice it is almost impossible to mix inks correctly and consistently. Looking trates the color space made up of the at this cube we see that yellow is represented by three colors red. CMY is often used for dyes and filters. In color space coordinates. This color space is called CMYK. The line that runs between the white and black corner represents all gray colors.
In effect. Each the coordinates 1. If you have another look at the RGB cube in figure 1. The largest possible value for the black K component is determined by taking the lowest of the CMY components.
When we see a color. The two most common ones are HSV for Hue. Lightness and Saturation. Appendix B contains the algorithms for conversion to and from these color spaces. Printers do not necessarily always subtract the largest amount of black from the individual colors.
The colors on the circle are arranged in the same order as they are on the rainbow. And finally we take note of the brightness of the color. And even when the black component of a color is treated separately. Many people feel that a color is most naturally identified with these color spaces. Hue is normally expressed as a value from 0 to All the colors with the same hue form a plane in the RGB color cube. Before looking at those. Some color spaces identify a color by its hue.
See figure 1. The lightness and value are slightly different quantities. A color with a saturation of 1 is pure. These planes form triangles inside the RGB color cube. An example of constant lightness can be seen in figure 1. This is. The planes of constant lightness and value are difficult to draw. All the colors with the same saturation but varying hue and value fall on a cone in the RGB color cube.
Pastel colors are colors with a low saturation. The saturation of a color expresses how pure the hue is. Note that the cube has been rotated 90 degrees around the blue axis. The tips of the figure remain stationary. Represented is a point that has a Hue of degrees and therefore points in the direction of the blue corner. The three-dimensional figure becomes narrower when the lightness value decreases. The figure grows smaller and closer to the origin when the value decreases.
The component that everything revolves around in these color spaces is the Luminance. The most common of these are YUV. This corresponds to a dark. This means that one of the three components expresses how bright the color is. The scale factors used in these color systems are just not appropriate outside their application domain. See for example the reference entries . The exact magnitude of these scaling factors is not important for this discussion.
It is capable only of expressing the relative brightness of pixels. In fact. YIQ and YCbCr One group of color spaces that is often used in video specifications expresses color as one component of luminance.
There are several ways to 2 3 12 It should be understood that this just is a schematic indication of the coordinates. Both of these are highly unportable. The length of the various arrows is not directly related to the HSV coordinates. YCbCr is more appropriate.
Conversion from a real color space to grayscale is a one-way process. Suffice it to say that they normally would be encountered only when working with video.
This generally renders the most natural result. This distance is used to calculate how similar two colors are. The eye is much less sensitive to blue than it is to red. Both are often easily implemented in software.
The distance in a color space is defined in the same way that a distance in geometrical space is defined: B Luminance is. Some color spaces such as YUV provide distances that are more closely related to the way our perception of color works than the more standard RGB color space. The most frequently used conversions are: Indexed image formats store all available colors in a palette or color map. Brightness is simply the average of the three color components. Doing these operations in different color spaces can result in visibly different images.
The scaling factors in the equation for luminance attempt to reflect this difference in sensitivity. The color distance is most important when reducing the numbers of colors in an image. A different color space will yield a different distance between the same colors. Chapter 4 has more practical information on how to work with graphics primitives. This method will remap the colors of the current image into the ones of the image argument.
Magick provides a built-in image type to convert images to that particular palette: You create an image. This can result in remarkable savings in disk space. Apart from print publications. The images will need to be stored somewhere for easy retrieval and indexing.
As an example: You receive digital images by email from correspondents and clients. All in all. This can vary from obtaining information about a single image. There is advertising artwork to be displayed. These images come from a variety of sources. You have professional photographers who go out and take photographs of interesting subjects with expensive cameras. Most are not in a suitable format for display on your web site.
Part of the content is.
Up until now. One example of this is GIF animation. Some image formats allow you to store more than one image in a single file or data stream. Each pixel stands on its own. The management. Other examples 1 16 Of course there are graphics formats and languages that allow both.
Given a set of business rules for a certain category of images. A circle is stored as the coordinates of the center and the radius. Most commonly. Image formats store graphics as a two-dimensional array of pixels.
Reading them back in is another matter. This chapter will deal with some file formats in which graphics can be stored.
Central to all of the above is the handling of graphics files and the information contained in them. It should also provide an interface that makes it possible to find an image with relative ease.
This allows for a good scalability of the image. These formats can be roughly divided into two groups: Some will allow you to express a certain relationship between all of these images. Perl can be easily used to create files of that type.
Many modules can create vector graphics for output. These formats contain no information about whether sections are parts of a circle. Another way to lose information is by color reduction. The fact that the GIF format is so old shows in the limitation of colors per data stream or per image.
There is a wealth of information available on the net covering the various graphics formats and their use and abuse [8. Some file formats are not well suited for storing images for further processing because they are lossy. For an RGB image in which each color component can have an integer value between 0 and The ways in which these layers can relate to each other are too numerous to list. A format such as JPEG uses some clever algorithmic techniques that can dramatically diminish the amount of data to be stored for photographic images.
It is. The idea behind GIF was to facilitate the reduction of the size of bitmap files so that transport over modems would be faster.
If you read this image later. There is much confusion about whether a license is also required for LZW decompression. A few of these repetitions can result in a considerable loss in quality. The main reason for this limitation is that the use of graphics on the Web is a mess. Some image formats store colors not per pixel. I will only discuss a very small subset here. The main relationship between the layers is how they are combined with other layers below them in the stack.
This is due to a lack of understanding regarding which format to use for which picture. There is still a way to use GIF. JFIF images work with a bit color space 16 million colors. Even if your application is made available for free. The second reason disappears when you no longer have to cater to obsolete software. The compression technique itself is known as JPEG compression. The libungif C library relies on that feature for creation of GIF images that are not subject to the patent.
It is not as good at images where most of the neighboring pixels have the same color. This license. In practice. An interesting detail is that a lot of commercial software. JPEG is a lossy format. The format allows for many image format features and compression schemes including LZW compression.
PNG is a lossless image format. SVG is clearly aimed at bringing more sane graphics to the Web by providing a standardized vector graphics format that is easy to parse and is transportable. The language is a W3C recommendation.
Apart from this baseline it also defines many extensions that applications can optionally implement. It has been around for a long time. For all practical purposes.
The TIFF format specifies a baseline set of features that every compliant application should support. MNG is the answer to the desire of web designers to include animated images on their sites.
As the name suggests. The TIFF format is mainly intended for images originating from scanners and other imaging devices. Support for this format in the major web browsers is also growing. Together with the bit color and bit grayscale support. Support for the SVG format is still limited.
In the case of image files. The last argument on the use Image:: Size line is a directive to the standard Perl exporting mechanism.
The tag: Size module. The TIFF format allows multiple images per file. The imgsize subroutine takes either a file name or an open file handle as its argument. Once you have such data. This can also be handy if you get your image data from a source other than a file.
Many modules make some of their internal names optionally available for export.
Size For most Perl applications. It will handle the most commonly used image formats and it is easy to use. This makes it a suitable format for storing images to use as a source.
Size qw: Magick If you have images in a format that Image:: As a bonus you also get the size in bytes and format of the image. Note that most Image:: Magick methods return undef on success.
Size also offers two convenient methods. A further explanation of this method appears on page Magick is a fairly large and heavy module. The reason for this is that Image:: Magick is a very general purpose graphics manipulation module. The simplest is to use a more powerful module.
There are some exceptions to this rule. This can be a bit counterintuitive. The subroutines will return the same values as the imgsize subroutine from Image:: The translation of the unpack 6 22 Generally. By localizing the file handle. This chunk first contains a 4-byte integer. Magick just for this might be too expensive. In more modern versions of Perl post 5. In this subroutine. If you need to know some information on only one or two images.
For example. In PNG. If we translate this knowledge into Perl code. As an illustration. We read from the source code that the first 9 bytes contain a fixed header. We capture the version as the last 4 bytes of this string. The first thing to be noted about the XCF format is that.
To round things off. Unknown version. The only difference for our purposes is the version number in the header of the file. The width and height of the image are the next two 4-byte integers: The second return value of the unpack operation. The XCF version 0 format formerly had the first 13 bytes set to gimp xcf file. See the documentation for a full list.
Table 2. If none of the modules can handle it. Format 24 Description BMP. Some of the formats that can be read by Image:: Magick are listed in table 2. This module can read and write a wide variety of image formats.
Some of these formats are parsed with the help of external modules or programs which require you to install these before compiling Image:: Magick module. For a complete list. The Write method can be used to save images to disk. Magick has some built-in format specifiers. These formats are not really image formats. If neither a file extension or explicit format are specified. We read in a GIF format file. We will discuss some concrete examples after showing the code that you will find at the start of almost any Perl program using Image:: In addition to standard external image formats.
Magick will usually be able to guess the file type by its signature.
If the file extension cannot be used. It uses the extension of the file name specified to determine the format to save. Each format has its own characteristic sequence of bytes. Figure 2. The result can be seen in figure 2. To create an image with a gradient going from light to dark gray the following code can be used: Then we create a white tile of 70 by 70 pixels. This is hopefully sufficient to provide a solid base from which to work with image files and the various formats that are available.
If this were not done. The Image:: Size module comes equipped with useful documentation which is recommended reading for anyone wishing to use the module.
Magick documentation and the reference in appendix A should be consulted for more information on the various Image:: Magick methods discussed. Magick was demonstrated. Magick gradients always run from top to bottom. When necessary it has been noted where to find the tools and their documentation. This chapter provides a list of software tools and modules used in this book. This is an excellent way to package knowledge about a certain protocol. They have spent time creating software libraries and modules.
Many programmers have done this. One of the strengths of Perl is that it provides a good interface for developers to create modules that can be reused by others. Apart from Perl modules. For platforms where these tools are not as standard. I suggest you use the CPAN distribution. While these platform-specific archives are convenient. Sometimes modules in these archives can grow severely out of date with respect to the latest versions on CPAN.
If you use MacPerl. The ActiveState ppm installation program will extract 1 28 http: To find out more about it. PL make make test make install or.
ActiveState distributes the de facto standard Perl for the bit Microsoft Windows platforms. The modules that are interfaces to C libraries or contain C code. If the module needs any form of byte code compilation. On Unix systems this documentation will also be extracted and made available as standard manual pages.
The company also maintains an archive of prepackaged and precompiled modules in the ActivePerl-specific ppm format. The documentation for the modules from CPAN is normally contained in the module source code itself. To get ActivePerl. On Unix and most other platforms. ActivePerl comes bundled with a tool. The distribution mechanism is. The modules are distributed as gzipped tar archives. Most of the modules can be found on CPAN http: GnuPlot provides an interface to gnuplot. It offers a simple.
This new version most likely will be released with a version number of 2. The program can be used interactively. For MacPerl. A full set of documentation comes with the modules. Included is a short description of what each module does and where to find occurrences of its use in the book.
Specific notes about where to obtain the module. The modules were originally created by David Bonner. The documentation may be installed separately. It supports a wide variety of chart and data types. Examples of the use of these modules can be found in section 5. The interface originally borrowed a lot of the ideas from GIFgraph but it has since gone its own way. WBMP Windows bitmap. Section 5. You will find several references in this book to the shortcomings of GD where color is concerned.
These examples have been tested with gnuplot version 3. I suspect that the next major release of GD will do this as well. GD only supports palettes of up to colors. Older versions before 1. GIFgraph and GD:: Graph were written and are maintained by the author. GIFgraph and Chart:: Both GIFgraph and Chart:: PNGgraph exist nowadays only to provide backward compatible name space wrappers around GD:: Graph directly.
The code in this book has been tested with GD:: Graph version 1. They were created during the writing of chapter 11 of this book by the author.
The Gimp is available from http: Graph comes with a set of reasonably complete documentation. The module is only sparsely used in this book. The Gimp itself is an interactive program. The Gimp Perl modules can be complex. Code that uses the GD:: Text modules can be found in section The code there has been tested with GD version 1. Graph and friends. Text version 0. Magick Image:: Magick is an object-oriented interface to ImageMagick.
These modules can be used to write command line programs. A full set of documentation is included in the modules. Fu Perl modules. GD comes with an excellent manual page. Text The GD:: Text module and its cousins GD:: Align and GD:: Wrap provide a generic interface to string handling and font management for the GD module.
PNGgraph was created by Steve Bonds. The other two subroutines are merely convenience wrappers around imgsize. Magick as compatible with the presented code as possible. Older versions might lack some of the presented functionality. The modules make sure that code gets compiled and loaded when needed.
It will read various file formats. Appendix A contains an introduction to and a reference for Image:: Size version 2. ImageMagick and its companion Perl module are written and maintained by John Cristy with the assistance of other developers.
The module comes with a helpful documentation page. Wherever possible. This helps to dramatically speed up subsequent executions. Binary distributions for several platforms including Microsoft Windows are available from the ImageMagick web pages see .
The standard Inline distribution. Its main subroutine. The module is available as part of the ImageMagick distribution under the name PerlMagick. When the code is compiled. Examples using the modules are presented throughout the book. You can pass it either a string containing a file name. John Cristy is aware of this book. ImageMagick uses a multitude of external libraries and programs.
The code in this book should run with Image:: Magick version 5. If you download the module from CPAN. The module is maintained by Randy Ray. Size This lightweight Perl module is intended mainly to be used in determining the size of image files. This freely available.
You can either buy a commercial implementation of the library. Examples of the use of OpenGL modules can be found in section 9. Version 0. An example of the use of Inline:: C is available in section According to the documentation. To use this module you must first have OpenGL installed on your system.
The Perl module. It creates charts and plots for all kinds of data. See the note on page The latest version on CPAN is 0. At the time of this writing. Some operating systems come with the required libraries installed and available. Python and CPR. Ruby and Bash are in the making. In addition to the documentation. The code in this book was run with Inline version 0. Ilya Zakharevich has added some portability code. At some point in the not too distant future these updated versions will probably be made accessible by CPAN.
The code in this section was tested against RenderMan 0. PL and comment out the references to libgd. To work with the output of this module. Rudimentary documentation is available for both Term:: Gnuplot and Term:: The code in this book has been tested and run with Term:: Gnuplot 0.
The only downside is that the set of drawing commands is fairly limited. I noticed that it expects your version of libgd to provide GIF output. The version used for these examples was 2. Gnuplot Term:: Gnuplot provides a Perl interface to the output drivers that are part of the gnuplot program. The rendering engine can choose any method it pleases to create computer graphics from the described scene. The RenderMan module cannot be compiled against version 2.
The standard commercial one is Photorealistic RenderMan. It offers a set of drawing primitives useful for any drawing task. Gnuplot was created and is maintained by Ilya Zakharevich.
Some examples of how to use Term:: Gnuplot are found in section 4. The RenderMan module is further described in section 9. Changing the output format of a program simply becomes a matter of changing the output driver. When you start using newer versions than those mentioned here— and that time will come—there are no guarantees that the code will still perform identically.
Magick has been released with only minor version number changes. Refer to this chapter whenever you need to install modules or programs used in the example code in this book. When minor numbers change.
In general. We are not seers. Chapter 8 shows various ways in which whole images can be manipulated and combined. In chapter 4 we will look at how to create your own drawings. Chapter 6 offers methods to dynamically create and serve graphics on your web site.
The subject matter ranges from the use of lowlevel drawing of squares. Chapter 5 provides an introduction to the various ways you can create graphs and charts in your Perl program. In the most basic sense. This part of the book covers how to do this. All drawing packages also have in common a coordinate space in which to work. Gnuplot 55 4.
When the result needs to be imported in another package. Magick 53 4. Throughout the book you will find many ways in which to create graphics. It is always possible to translate between these different coordinate systems. Magick 46 4. What these coordinates express depends on the drawing package: No matter which drawing package you use. For some graphics applications.
Perl modules or otherwise. Many primitives can be specified in several ways. Even though most drawing packages provide these primitives. The differences between drawing packages starts with the definition of a coordinate system. GD and Image:: Some drawing packages work in real-life coordinates. Figure 4.
The drawing primitives for almost all graphics packages. The handling of text is generally more complex than the other primitives. One could argue that all that is really needed are a line and an arc. A circle can be specified as the coordinate of its center and a radius. These issues will be discussed in section 4. One other previously mentioned primitive. It can also be specified as three points that are not on a straight line.
Graphics Programming with Perl. Martien Verbruggen. Source Code Figures Book Forum show all. Table of Contents detailed table of contents. Who should read this book? Source code downloads. Overview of graphics 1. Perl and graphics. The bits and pieces in graphics programming. Color spaces and palettes 1.
Reducing the number of colors in an image. Overview of graphics file formats 2. Some graphics formats 2.
Finding the size and type of an image 2. More on file size and information. Conversion of graphics formats. Overview of tools and modules 3. The tools 3. The Chart:: Graph, GIFgraph and Chart:: Drawing 4. Drawing with GD 4. An example drawing. Drawing with Image:: Magick 4. Drawing text with Image:: Combining GD and Image:: Creating charts 5.
Graph and friends 5. Preparing your data sets for GD:: Controlling the look of your chart. Lines, Points and LinesPoints charts.
The Chart distribution 5. Pareto charts. Graphics and the Web 6. The Common Gateway Interface 6. Suitable image formats 6. Web safe color palettes. CGI and dynamically generated graphics. Forms and encapsulated graphics. Image collections and thumbnailing 6. Thumbnails with Image:: Contact sheets with Image:: An example application: A web photo album. Animations for the Web 7. Animation file formats 7. Repeatedly applying a filter 7. Zooming in on an object.
Resizing and combining images 8. Scaling and cropping an image 8. Magick geometry specification. Combining Images 8. Combining GD images. Combining Image:: Magick images. Adding a watermark to an image. Three-dimensional graphics 9. OpenGL 9. OpenGL library functions in Perl. RenderMan 9. How to use the module and the BMRT. The RenderMan language binding for Perl. A rotating cube of cubes. Writing your own graphics modules Interface design Coordinate transformation.
Choosing your drawing primitives. An OO implementation of a clock. Controlling text placement