GD Shapes
<?php
// sample to print out some shapes as png picture.
// to view source call with: gd_shapes.php?viewsource=1
// call f.e. with: gd_shapes.php?b=4&interlace=1
// v0.14 20-Sep-2004, by G. Knauf <efash@gmx.net>
if ($_GET['viewsource']) {
echo highlight_string(file_get_contents($_SERVER['SCRIPT_FILENAME']));
die;
}
extension_loaded('gd') or die ("Error: GD extension not loaded!");
$im = @ImageCreate (300, 300);
$white = ImageColorAllocate ($im, 255, 255, 255);
$black = ImageColorAllocate ($im, 0, 0, 0);
$red = ImageColorAllocate ($im, 255, 0, 0);
$blue = ImageColorAllocate ($im, 0, 0, 255);
$yellow = ImageColorAllocate ($im, 255, 250, 205);
$green = ImageColorAllocate ($im, 0, 255, 0);
ImageColorTransparent($im, $white); # white color is transparent
if ($_GET['interlace'])
ImageInterlace($im, 1); # cool venetian blinds effect
# Create a flat wide rectangle paintbrush
$brush = @ImageCreate (10,10);
$white = ImageColorAllocate ($brush, 255, 255, 255);
$black = ImageColorAllocate ($brush, 0, 0, 0);
ImageColorTransparent($brush, $white); # white color is transparent
ImageFilledRectangle($brush, 0, 0, 5, 2, $black); # a black rectangle
# Draw a friendly title (ha!)
define ("gdTinyFont", 1);
define ("gdSmallFont", 2);
define ("gdMediumBoldFont", 3);
define ("gdLargeFont", 4);
ImageString($im, gdLargeFont,150,10,"Hello world!",$red);
ImageString($im, gdSmallFont,150,28,"Goodbye cruel world!",$blue);
ImageStringUp($im, gdTinyFont,280,250,"I'm climbing the wall!",$green);
ImageCharUp($im, gdMediumBoldFont,280,280,"Q",$black);
# Draw an oval
ImageSetBrush ($im, $brush);
ImageArc ($im, 100, 100, 100, 150, 0, 360, IMG_COLOR_BRUSHED);
$poly = array (30,30, 100,10, 190,290, 30,290);
ImagePolygon ( $im, $poly, 4, IMG_COLOR_BRUSHED);
ImageFill ($im,132,62,$blue);
ImageFill ($im,100,70,$red);
ImageFill ($im,40,40,$yellow);
# print the image to stdout
Header("Content-type: image/png");
ImagePng ($im);
ImageDestroy ($im);
?>