05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter CHAPTER 9 9<br />

Graphics<br />

The Web is more than just text. Images appear in the form of logos, buttons, photographs,<br />

charts, advertisements, and icons. Many of these images are static, built with<br />

tools such as PhotoShop and never changed. But many are dynamically created—<br />

from advertisements for Amazon’s referral program that include your name to<br />

Yahoo! Finance’s graphs of stock performance.<br />

<strong>PHP</strong> supports graphics creation with the GD and Imlib2 extensions. In this chapter<br />

we’ll show you how to generate images dynamically with <strong>PHP</strong>, using the GD<br />

extension.<br />

Embedding an Image in a Page<br />

A common misconception is that there is a mixture of text and graphics flowing<br />

across a single HTTP request. After all, when you view a page you see a single page<br />

containing such a mixture. It is important to understand that a standard web page<br />

containing text and graphics is created through a series of HTTP requests from the<br />

web browser, each answered by a response from the web server. Each response can<br />

contain one and only one type of data, and each image requires a separate HTTP<br />

request and web server response. Thus, if you see a page that contains some text and<br />

two images, you know that it has taken three HTTP requests and corresponding<br />

responses to construct this page.<br />

Take this HTML page, for example:<br />

214<br />

<br />

<br />

Example Page<br />

<br />

<br />

This page contains two images.<br />

<br />

<br />

<br />

<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!