Chapter 9. Graphics
The Web is more than just text. Images appear in the form of logos, buttons, photographs, charts, advertisements, and icons. Many of these images are static, built with tools such as PhotoShop and never changed. But many are dynamically created—from advertisements for Amazon’s referral program that include your name to Yahoo! Finance’s graphs of stock performance.
PHP supports graphics creation with the GD and Imlib2 extensions. In this chapter we’ll show you how to generate images dynamically with PHP, using the GD extension.
Embedding an Image in a Page
A common misconception is that there is a mixture of text and graphics flowing across a single HTTP request. After all, when you view a page you see a single page containing such a mixture. It is important to understand that a standard web page containing text and graphics is created through a series of HTTP requests from the web browser, each answered by a response from the web server. Each response can contain one and only one type of data, and each image requires a separate HTTP request and web server response. Thus, if you see a page that contains some text and two images, you know that it has taken three HTTP requests and corresponding responses to construct this page.
Take this HTML page, for example:
<html>
<head>
<title>Example Page</title>
</head>
<body>
This page contains two images.
<img src="image1.jpg" alt="Image 1">
<img src="image2.jpg" alt="Image 2">
</body>
</html>The series of requests sent ...