Page 264 - Open Soource Technologies 304.indd
P. 264
Web Technologies-I
Notes Again, lay your pointer on the image without clicking. You will see that it is active but does
not carry that annoying blue border. And that brings this to a close.
11.2 The Graphic Design(GD) Extension
The GD library is used for dynamic image creation. From PHP we use with the GD library to
create GIF, PNG or JPG images instantly from our code. This allows us to do things such as
create charts on the fly, create an anti-robot security image, create thumbnail images, or even
build images from other images.
PHP is not limited to create just HTML output. It can also be used to create and manipulate
image files in a variety of different image formats, including GIF, PNG, JPEG, WBMP, and XPM.
Even more convenient, PHP can output image streams directly to a browser. You will need to
compile PHP with the GD library of image functions for this to work. GD and PHP may also
require other libraries, depending on which image formats you want to work with.
You can use the image functions in PHP to get the size of JPEG, GIF, PNG, SWF, TIFF and
JPEG2000 images.
With the exif extension, you are able to work with information stored in headers of JPEG and
TIFF images. This way you can read metadata generated by digital cameras. The exif functions
do not require the GD library.
PHP 4.3 is a bundled version of the GD lib. This bundled version has some
additional features like alpha blending, and should be used in preference to
the external library since it is codebase is better maintained and more stable.
With the assistance of the GD library, you can use PHP to create applications that use dynamic
images to display stock quotes, reveal poll results, monitor system performance, and even create
games. However it is not like using Photoshop or GIMP; you cannot draw a line by moving
your mouse. Instead, you need to precisely specify a shape’s type, size, and position.
GD has an existing API, and PHP tries to follows its syntax and function-naming conventions.
So, if you are familiar with GD from other languages, such as C or Perl, you can easily use GD
with PHP. If GD is new to you, it may take a few minutes to figure it out, but soon you will
be drawing like Picasso.
The feature set of GD varies greatly depending on which version GD you are running and which
features were enabled during configuration. Versions of GD up to 1.6 supported reading and
writing GIFs, but this code was removed due to patent problems. Instead, newer versions of
GD support JPEGs, PNGs, and WBMPs. Because PNGs are generally smaller than GIFs, allow
you to use many more colours, have built-in gamma correction, and are supported by all major
web browsers, the lack of GIF support is classified as a feature, not a bug.
Besides supporting multiple file formats, GD lets you draw pixels, lines, rectangles, polygons,
arcs, ellipses, and circles in any colour you want.
You can also draw text using a variety of font types, including built-in, TrueType, and PostScript
Type 1 fonts. The ins and outs of the three main text-drawing functions. These two recipes form
the basis combines an image template with real-time data to create dynamic images. GD also lets
you make transparent GIFs and PNGs. Setting a colour as transparent and using transparencies
in patterns.
All these features work with GD 1.8.4, which is the latest stable version of the library. If you
have an earlier version, you should not have a problem. However, if a particular recipe needs
a specific version of GD, we note it in the recipe.
258 LOVELY PROFESSIONAL UNIVERSITY