13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

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

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

Using Text <strong>and</strong> Fonts to Create Images<br />

491<br />

n You can write the image out to a file, as previously mentioned, <strong>and</strong> then refer to it<br />

with a normal tag.<br />

n You can put the image production script in an image tag.<br />

We have covered the first two methods already. Let’s briefly look at the third method<br />

now.To use this method, you include the image inline in HTML by having an image tag<br />

along the lines of the following:<br />

<br />

Instead of putting in a PNG, JPEG, or GIF directly, put in the <strong>PHP</strong> script that generates<br />

the image in the SRC tag. It will be retrieved <strong>and</strong> the output added inline, as shown in<br />

Figure 22.3.<br />

Figure 22.3<br />

The dynamically produced inline image appears the same as a<br />

regular image to the end user.<br />

Using Text <strong>and</strong> Fonts to Create Images<br />

Let’s look at a more complicated example of creating images. It is useful to be able to<br />

create buttons or other images for your website automatically.You can easily build simple<br />

buttons based on a rectangle of background color using the techniques we’ve already<br />

discussed.You can generate more complicated effects programmatically, too, but you can<br />

generally do it more easily in a paint program.This also makes it easier to get an artist to<br />

do the artwork <strong>and</strong> leave programmers programming.<br />

In this example, you generate buttons using a blank button template.This allows you<br />

to have features such as beveled edges <strong>and</strong> so on, which are a good deal easier to generate<br />

using Photoshop, the GIMP, or some other graphics tool.With the image library in<br />

<strong>PHP</strong>, you can begin with a base image <strong>and</strong> draw on top of that.

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

Saved successfully!

Ooh no, something went wrong!