<!-- Here is the page source code for 05imageCreate.php -->
<?php
// TELL OUTPUT STREAM TO EXPECT PNG IMAGE DATA
header( "Content-type: image/png");
// CREATE THE IMAGE
$image = imagecreate(400, 200); // Create a new 400x200 image
// SET UP SOME COLOURS
$yellow = imagecolorallocate($image, 255, 255, 0); // create color R=255, G=255, B=0
$cyan = imagecolorallocate($image, 0, 255, 255); // create color R=0, G=255, B=255
$red = imagecolorallocate($image, 255, 0, 0); // create color red
$blue = imagecolorallocate($image, 0, 0, 255); // create color blue
// DRAW SOME SHAPES
imagefilledrectangle($image, 0, 0, 400, 200, $cyan); // create cyan background
imagefilledrectangle($image, 10, 80, 390, 190, $yellow); // create inner yellow rectangle
imagerectangle ($image, 5, 5, 395, 195, $red); // create red frame
// PLOT SOME CONTENTS
imageline($image, 10, 135, 390, 135, $red); // a line
// PLOT A SINE WAVE
for ($i = 0; $i < 3800; $i++)
{
$y = 135 - 50 * sin($i / 100); // Calculate y value
imagesetpixel($image, 10 + $i / 10, $y, $red); // Plot a red pixel
}
// PLOT A COSINE WAVE
for ($i = 0; $i < 3800; $i++)
{
$y = 135 - 50 * cos($i / 100); // Calculate y value
imagesetpixel($image, 10 + $i / 10, $y, $blue); // Plot a blue pixel
}
// DISPLAY SOME TEXT
for ($i = 1; $i <= 5; $i++)
{
// display 5 built-in fonts in red
// image font x y display-this-text colour
imagestring($image, $i, 15, $i * 12, 'Sine wave (red) Cosine wave (blue)', $red);
}
imagepng($image); // Stream the image output as it it came from a file
imagedestroy($image); // Cleanup memory
?>
|