Page 277 - Open Soource Technologies 304.indd
P. 277
Unit 11: Graphics
list($x, $y) = pc_ImagePSCenter($image, $text, $font, $size); Notes
ImagePSText($image, $text, $font, $size, $color, $bg_color, $x, $y);
// Send image
header(‘Content-type: image/png’);
ImagePNG($image); // Clean up Image
PSFreeFont($font);
ImageDestroy($image);
}
else {
?>
<html>
<head>
<title>Sample Button Page</title>
</head>
<body>
<img src=”<?php echo $_SERVER[‘PHP_SELF’]; ?>?button=Previous” alt=”Previous”
width=”132” height=”46”>
<img src=”<?php echo $_SERVER[‘PHP_SELF’]; ?>?button=Next” alt=”Next” width=”132”
height=”46”>
</body>
</html>
<?php } ?>
Figure 11.10: Sample Button Page
In this script, if a value is passed in for $_GET[‘button’], we generate a button and send out
the PNG. If $_GET[‘button’] is not set, we print a basic HTML page with two embedded calls
back to the script with requests for button images — one for a Previous button and one for a
Next button. A more general solution is to create a separate button.php page that returns only
graphics and set the image source to point at that page.
11.7 Scaling Images
One of the most basic features of computers today is the ability to edit graphics. Many times, you
need to build web applications that take image data from users and scale it down to a format
that can easily be displayed on your website. Fortunately, PHP ships with the very powerful
LOVELY PROFESSIONAL UNIVERSITY 271