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.

Example 9-12. A gray rectangle with a 50% alpha channel overlaid<br />

<br />

Figure 9-12 shows the output of Example 9-12 (alpha blending is still turned off).<br />

Figure 9-12. A gray rectangle over the orange ellipse<br />

If we change Example 9-12 to enable alpha blending just before the call to<br />

ImageFilledRectangle( ), we get the image shown in Figure 9-13.<br />

Figure 9-13. Image with alpha blending enabled<br />

Identifying Colors<br />

To check the color index for a specific pixel in an image, use ImageColorAt( ):<br />

$color = ImageColorAt(image, x, y);<br />

For images with an 8-bit color palette, the function returns a color index that you<br />

then pass to ImageColorsForIndex( ) to get the actual RGB values:<br />

$values = ImageColorsForIndex(image, index);<br />

The array returned by ImageColorsForIndex( ) has keys "red", "green", and "blue". If<br />

you call ImageColorsForIndex( ) on a color from a true color image, the returned<br />

array has an extra key, "alpha".<br />

230 | Chapter 9: Graphics<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!