( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ
<?php
/*
* Class: shadowgd
*
* This class lets you draw the basic shapes in the GD graphics
* module-- rectangle, polygon, ellipse and arc -- with a drop shadow.
* The user can set the drop shadow's size, color and direction, as
* well as specify whether an outline (and it's color) should be
* drawn around the shape.
*
* Author: Andrew Wilson
* Email: projects@ajwwebservices.com
*
*/
class shadowgd
{
/********* variables *********/
var $image;
var $shadow_size;
var $shadow_direction;
var $lt_shadow_color;
var $drk_shadow_color;
var $outline_color;
/********* CLASS CONSTRUCTOR *********/
function shadowgd ($img)
{
$this->image = $img;
// set default shadow params
$lt_gray = ImageColorAllocate($this->image, 204, 204, 204);
$drk_gray = ImageColorAllocate($this->image, 102, 102, 102);
$this->SetShadow (4, 3, $lt_gray, $drk_gray);
// set default outline params
$blk_outline = ImageColorAllocate($this->image, 0, 0, 0);
$this->SetOutlineColor($blk_outline);
return;
}
/********* Function: SetShadow *********/
// This function is used to set the size and direction of the drop
// shadow, and the two shades of color to be used in drawing it.
function SetShadow ($size, $direction, $lt_shadow, $drk_shadow)
{
$this->shadow_size = $size;
$this->shadow_direction = $direction;
$this->lt_shadow_color = $lt_shadow;
$this->drk_shadow_color = $drk_shadow;
return;
}
/********* Function: SetOutlineColor *********/
// This function is used to set the color of the outline to be drawn
// around a shape if the user specifies an outline.
function SetOutlineColor ($outln_clr)
{
$this->outline_color = $outln_clr;
return;
}
/********* Function: DrawShadowPolygon *********/
// This function is used to draw the user-specified polygon shape with
// a drop shadow.
//
// Arguments:
// $polygon_outline array containing (x,y) coords of polygon vertices
// $polygon_color color to fill polygon
// $show_outline flag specifying whether to draw an outline
//
//
// Returns: nothing
//
function DrawShadowPolygon ($polygon_outline, $polygon_color, $show_outline = true)
{
$num_points = count($polygon_outline) / 2;
if (($num_points != 0) && is_int($num_points))
{
// draw shadow layers
$shadow_outline = $this->FindShadowPos($polygon_outline, $this->shadow_size);
ImageFilledPolygon($this->image, $shadow_outline, $num_points, $this->lt_shadow_color);
$shadow_outline = $this->FindShadowPos($polygon_outline, ($this->shadow_size / 2));
ImageFilledPolygon($this->image, $shadow_outline, $num_points, $this->drk_shadow_color);
// draw polygon
ImageFilledPolygon($this->image, $polygon_outline, $num_points, $polygon_color);
// draw outline if wanted
if ($show_outline)
{
ImagePolygon($this->image, $polygon_outline, $num_points, $this->outline_color);
}
}
return;
}
/********* Function: DrawShadowRectangle *********/
// This function is used to draw the user-specified rectangle with a drop shadow.
//
// Arguments:
// $rect_coords array containing (x,y) coords of upper left and lower
// right corners of rectangle
// $rect_color color to fill rectangle
// $show_outline flag specifying whether to draw an outline
//
//
// Returns: nothing
//
function DrawShadowRectangle ($rect_coords, $rect_color, $show_outline = true)
{
if (count($rect_coords) == 4)
{
// draw shadow layers
$shadow_outline = $this->FindShadowPos($rect_coords, $this->shadow_size);
ImageFilledRectangle($this->image, $shadow_outline[0], $shadow_outline[1], $shadow_outline[2], $shadow_outline[3], $this->lt_shadow_color);
$shadow_outline = $this->FindShadowPos($rect_coords, ($this->shadow_size / 2));
ImageFilledRectangle($this->image, $shadow_outline[0], $shadow_outline[1], $shadow_outline[2], $shadow_outline[3], $this->drk_shadow_color);
// draw rectangle
ImageFilledRectangle($this->image, $rect_coords[0], $rect_coords[1], $rect_coords[2], $rect_coords[3], $rect_color);
// draw outline if wanted
if ($show_outline)
{
ImageRectangle($this->image, $rect_coords[0], $rect_coords[1], $rect_coords[2], $rect_coords[3], $this->outline_color);
}
}
return;
}
/********* Function: DrawShadowEllipse *********/
// This function is used to draw the user-specified ellipse with a drop shadow.
//
// Arguments:
// $ellipse_center array containing (x,y) coords of ellipse center
// $ellipse_width width of ellipse
// $ellipse_height height of ellipse
// $ellipse_color color to fill ellipse
// $show_outline flag specifying whether to draw an outline
//
//
// Returns: nothing
//
function DrawShadowEllipse ($ellipse_center, $ellipse_width, $ellipse_height, $ellipse_color, $show_outline = true)
{
if (count($ellipse_center) == 2)
{
// draw shadow layers
$shadow_outline = $this->FindShadowPos($ellipse_center, $this->shadow_size);
ImageFilledEllipse($this->image, $shadow_outline[0], $shadow_outline[1], $ellipse_width, $ellipse_height, $this->lt_shadow_color);
$shadow_outline = $this->FindShadowPos($ellipse_center, ($this->shadow_size / 2));
ImageFilledEllipse($this->image, $shadow_outline[0], $shadow_outline[1], $ellipse_width, $ellipse_height, $this->drk_shadow_color);
// draw ellipse
ImageFilledEllipse($this->image, $ellipse_center[0], $ellipse_center[1], $ellipse_width, $ellipse_height, $ellipse_color);
// draw outline if wanted
// (use ImageArc because of bug with ImageEllipse)
if ($show_outline)
{
ImageArc($this->image, $ellipse_center[0], $ellipse_center[1], $ellipse_width, $ellipse_height, 0, 360, $this->outline_color);
}
}
return;
}
/********* Function: DrawShadowArc *********/
// This function is used to draw the user-specified arc (pie wedge) with a drop shadow.
//
// Arguments:
// $arc_center array containing (x,y) coords of arc center
// $arc_width width of arc
// $arc_height height of arc
// $arc_start starting point of arc, in degrees
// $arc_end ending point of arc, in degrees
// $arc_color color to fill arc
// $show_outline flag specifying whether to draw an outline
//
//
// Returns: nothing
//
function DrawShadowArc ($arc_center, $arc_width, $arc_height, $arc_start, $arc_end, $arc_color, $show_outline = true)
{
if (count($arc_center) == 2)
{
// draw shadow layers
$shadow_outline = $this->FindShadowPos($arc_center, $this->shadow_size);
ImageFilledArc($this->image, $shadow_outline[0], $shadow_outline[1], $arc_width, $arc_height, $arc_start, $arc_end, $this->lt_shadow_color, IMG_ARC_PIE);
$shadow_outline = $this->FindShadowPos($arc_center, ($this->shadow_size / 2));
ImageFilledArc($this->image, $shadow_outline[0], $shadow_outline[1], $arc_width, $arc_height, $arc_start, $arc_end, $this->drk_shadow_color, IMG_ARC_PIE);
// draw arc (wedge)
ImageFilledArc($this->image, $arc_center[0], $arc_center[1], $arc_width, $arc_height, $arc_start, $arc_end, $arc_color, IMG_ARC_PIE);
// draw outline if wanted
if ($show_outline)
{
ImageArc($this->image, $arc_center[0], $arc_center[1], $arc_width, $arc_height, $arc_start, $arc_end, $this->outline_color);
}
}
return;
}
/********* Function: FindShadowPos *********/
// This function is used to find the position of a shadow layer
//
// Arguments:
// $shape_coords array containing (x,y) coords of shape being drawn
// $distance distance shadow layer should be from parent shape
//
//
// Returns:
// $shadow_outline array containing (x,y) coords of shadow layer
//
function FindShadowPos ($shape_coords, $distance)
{
for ($i = 0; $i < count($shape_coords); $i = $i + 2)
{
switch ($this->shadow_direction)
{
case 0:
$shadow_outline[$i] = $shape_coords[$i];
$shadow_outline[$i+1] = $shape_coords[$i+1] - $distance;
break;
case 1:
$shadow_outline[$i] = $shape_coords[$i] + $distance;
$shadow_outline[$i+1] = $shape_coords[$i+1] - $distance;
break;
case 2:
$shadow_outline[$i] = $shape_coords[$i] + $distance;
$shadow_outline[$i+1] = $shape_coords[$i+1];
break;
case 3:
$shadow_outline[$i] = $shape_coords[$i] + $distance;
$shadow_outline[$i+1] = $shape_coords[$i+1] + $distance;
break;
case 4:
$shadow_outline[$i] = $shape_coords[$i];
$shadow_outline[$i+1] = $shape_coords[$i+1] + $distance;
break;
case 5:
$shadow_outline[$i] = $shape_coords[$i] - $distance;
$shadow_outline[$i+1] = $shape_coords[$i+1] + $distance;
break;
case 6:
$shadow_outline[$i] = $shape_coords[$i] - $distance;
$shadow_outline[$i+1] = $shape_coords[$i+1];
break;
case 7:
$shadow_outline[$i] = $shape_coords[$i] - $distance;
$shadow_outline[$i+1] = $shape_coords[$i+1] - $distance;
break;
}
}
return $shadow_outline;
}
// end class
}
?>