PHP Classes
elePHPant
Icontem

File: shadowgd_demo.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Andrew Wilson  >  shadowgd  >  shadowgd_demo.php  >  Download  
File: shadowgd_demo.php
Role: Example script
Content type: text/plain
Description: Class demo
Class: shadowgd
Draw GD graphics shapes with drop shadows
Author: By
Last change:
Date: 12 years ago
Size: 3,072 bytes
 

Contents

Class file image Download
<?php
require "shadowgdclass.php";

Header("Content-type: image/jpeg");
$demo_width = 600;
$demo_height = 500;
$image = ImageCreate($demo_width, $demo_height);
// set up colors
$lt_gray = ImageColorAllocate($image, 204, 204, 204);
$black = ImageColorAllocate($image,0,0,0);
$white = ImageColorAllocate($image, 255, 255, 255);
$lt_blue = ImageColorAllocate($image,51, 153, 204);
$drk_blue = ImageColorAllocate($image,0, 0, 153);
$blue_bkgd = ImageColorAllocate($image, 153, 255, 255);
$blue = ImageColorAllocate($image,0,0,255);
$green = ImageColorAllocate($image,0, 255, 0);
$red = ImageColorAllocate($image, 255, 0, 0);
// draw background
ImageFilledRectangle($image, 10, 10, $demo_width - 10, $demo_height / 2, $white);
ImageFilledRectangle($image, 10, $demo_height /2, $demo_width - 10, $demo_height - 10, $blue_bkgd);
ImageSetThickness($image, 5);
ImageRectangle($image, 10, 10, $demo_width - 10, $demo_height - 10, $black);
ImageSetThickness($image, 1);
// draw title
$title = "ShadowGD Demo";
$char_width = ImageFontWidth(5);
$title_width = strlen($title) * $char_width;
$title_x = 300 - ($title_width / 2);
ImageString($image, 5, $title_x, 20, $title, $black);

$grfx = new shadowgd($image);
// bar chart
// draw axes
ImageSetThickness($image, 4);
ImageLine($image, 43, 80, 43, 220, $black);
ImageLine($image, 43, 220, 270, 220, $black);
ImageSetThickness($image, 1);
// first bar
$shape_coords = array(45, 100, 170, 130);
$grfx->DrawShadowRectangle($shape_coords, $green);
// second bar
$shape_coords = array(45, 140, 200, 170);
$grfx->DrawShadowRectangle($shape_coords, $drk_blue);
// third bar
$shape_coords = array(45, 180, 250, 210);
$grfx->DrawShadowRectangle($shape_coords, $red);

// pie chart
$base_x = 425;
$base_y = 160;
ImageFilledArc($image, $base_x, $base_y, 100, 100, 0, 40, $red, IMG_ARC_PIE);
ImageFilledArc($image, $base_x, $base_y, 100, 100, 40, 200, $blue, IMG_ARC_PIE);
// find position of offset wedge
$wedge_angle = 280;
$arc_center[0] = $base_x - (15 * sin($wedge_angle));
$arc_center[1] = $base_y + (15 * cos($wedge_angle));
$grfx->DrawShadowArc($arc_center, 100, 100, 200, 360, $green, false);

// changing shadow params demo
// blue shadow, size 6, direction 0
$base_x = 150;
$base_y = 360;
$shape_coords = array($base_x, $base_y);
$grfx->SetShadow(6, 0, $lt_blue, $drk_blue);
$grfx->DrawShadowEllipse($shape_coords, 60, 40, $green);
// blue shadow, size 4, direction 1, no outline
$base_x = 380;
$base_y = 330;
$shape_coords = array($base_x, $base_y, $base_x + 40, $base_y + 40, $base_x + 40, $base_y + 70, $base_x, $base_y + 70);
$grfx->SetShadow(4, 1, $lt_blue, $drk_blue);
$grfx->DrawShadowPolygon($shape_coords, $red, false);
// blue shadow, size 4, direction 5
$base_x = 450;
$base_y = 330;
$shape_coords = array($base_x, $base_y, $base_x + 40, $base_y + 40, $base_x + 40, $base_y + 70, $base_x, $base_y + 70);
$grfx->SetShadow(4, 5, $lt_blue, $drk_blue);
$grfx->DrawShadowPolygon($shape_coords, $blue);

ImageJPEG($image);
ImageDestroy($image);

?>