error_reporting(0);
include("functions.php");
$h1 = "DJ Mike's Image Maker 2";
$h2 = "Breziers, Polygons & Polylines";
##
if ( $_GET[action] == "Reset" )
{
$_SESSION[fill_alpha] = NULL;
$_SESSION[fill_opacity] = NULL;
$_SESSION[stroke_alpha] = NULL;
$_SESSION[stroke_opacity] = NULL;
$_SESSION[stroke_color] = NULL;
$_SESSION[fill_color] = NULL;
$_SESSION[stroke_width] = NULL;
$_SESSION[poly_path] = NULL;
header("location:$self");
exit;
}
if ( $_GET[action] == "Polygon" ||
$_GET[action] == "Polyline" ||
$_GET[action] == "Bezier" )
{
# set stroke alpha
if ($_GET[stroke_alpha])
{
$stroke_alpha = trim($_GET[stroke_alpha] );
$stroke_alpha = (float)$stroke_alpha;
if ( $stroke_alpha < 0 ) { $stroke_alpha = 0; }
if ( $stroke_alpha > 1 ) { $stroke_alpha = 1; }
}
# set stroke opacity
if ($_GET[stroke_opacity])
{
$stroke_opacity = trim($_GET[stroke_opacity] );
$stroke_opacity = (float)$stroke_opacity;
if ( $stroke_opacity < 0 ) { $stroke_opacity = 0; }
if ( $stroke_opacity > 1 ) { $stroke_opacity = 1; }
}
# set stroke fill opacity
if ($_GET[fill_opacity])
{
$fill_opacity = trim($_GET[fill_opacity] );
$fill_opacity = (float)$fill_opacity;
if ( $fill_opacity < 0 ) { $fill_opacity = 0; }
if ( $fill_opacity > 1 ) { $fill_opacity = 1; }
}
# set stroke fill alpha
if ($_GET[fill_alpha])
{
$fill_alpha = trim($_GET[fill_alpha] );
$fill_alpha = (float)$fill_alpha;
if ( $fill_alpha < 0 ) { $fill_alpha = 0; }
if ( $fill_alpha > 1 ) { $fill_alpha = 1; }
}
#### validate color ##
if ( $_GET[fill_color] )
{
$fill_color = trim($_GET[fill_color] );
$fill_color = colors( $fill_color, "validate" );
if ( !$fill_color )
{ $error .= "Fill color is invalid
"; }
}
##
if ( $_GET[stroke_color] )
{
$stroke_color = trim($_GET[stroke_color] );
$stroke_color = colors( $stroke_color, "validate" );
if ( !$stroke_color )
{ $error .= "Stroke color is invalid
"; }
}
if ( $error )
{
$_SESSION[error] = $error;
header("location:$self");
}
#### end validate colors ##
#### if all vars set, make image & draw object
$image = new Imagick($_SESSION[path]);
$draw = new ImagickDraw;
$skewX = (float)$_GET[draw_skew_x];
$skewY = (float)$_GET[draw_skew_y];
$scaleX = (float)$_GET[draw_scale_x];
$scaleY = (float)$_GET[draw_scale_y];
if ( $scaleX == 0 ) { $scaleX = 1; }
$scaleY = (float)$_GET[draw_scale_y];
if ( $scaleY == 0 ) { $scaleY = 1; }
$deg = (float)$_GET[draw_rotate];
if ( $fill_color ) { $draw->setfillcolor("$fill_color"); }
if ( $stroke_color ) { $draw->setstrokecolor($stroke_color); }
# set width
$stroke_width = trim($_GET[stroke_width] );
$stroke_width = (int)$stroke_width;
if ( $stroke_width ) { $draw->setstrokewidth($stroke_width); }
# set stroke alpha/opacity & fill alpha/opacity
if ( $stroke_alpha ) { $draw->setstrokealpha($stroke_alpha); }
if ( $stroke_opacity ) { $draw->setstrokealpha($stroke_opacity); }
if ( $fill_opacity ) { $draw->setfillalpha($fill_opacity); }
if ( $fill_alpha ) { $draw->setfillalpha($fill_alpha); }
$draw->skewx($skewX);
$draw->skewy($skewY);
$draw->rotate($deg);
$draw->scale( $scaleX, $scaleY );
# set line cap
switch ($_GET[line_cap])
{
case "BUTT";
$cap = imagick::LINECAP_BUTT;
break;
case "ROUND";
$cap = imagick::LINECAP_ROUND;
break;
case "SQUARE";
$cap = imagick::LINECAP_SQUARE;
break;
default:
$cap = imagick::LINECAP_UNDEFINED;
}
$draw->setStrokeLineCap($cap);
###############################
# get corner points & draw shape
###############################
$poly_path = trim($_GET[coorids] );
# store before modifing
$_SESSION[poly_path] = $poly_path;
$poly_path = explode( " ", $poly_path );
foreach( $poly_path as $temp )
{
$temp = explode( ",", $temp);
if ( count($temp) == 2)
{
$x = (int)$temp[0];
$y = (int)$temp[1];
$points[] = array( "x"=>$x, "y"=>$y);
}
} # $points is array of polygon corners
if ( $_GET[action] == "Polygon" )
{ $draw->polygon( $points ); }
if ( $_GET[action] == "Polyline" )
{ $draw->polyline( $points ); }
if ( $_GET[action] == "Bezier" )
{ $draw->bezier( $points ); }
###############################
foreach ($image as $frame) { $frame->drawimage($draw); }
$format = strtolower( $image->getimageformat() );
$path = "temp/$ID.$_SESSION[views].$format";
$frames = $image->getNumberImages();
if ( $frames > 1) { $image->writeImages("$path", TRUE); }
else { $image->writeImage("$path"); }
# save settings
$_SESSION[draw_scale_x] = $scaleX;
$_SESSION[draw_scale_y] = $scaleY;
$_SESSION[stroke_width] = $stroke_width;
$_SESSION[fill_alpha] = $fill_alpha;
$_SESSION[fill_opacity] = $fill_opacity;
$_SESSION[stroke_alpha] = $stroke_alpha;
$_SESSION[stroke_opacity] = $stroke_opacity;
$_SESSION[path] = $path;
$_SESSION[fill_color] = $fill_color;
$_SESSION[stroke_color] = $stroke_color;
$_SESSION[x_round] = $x_round;
$_SESSION[y_round] = $y_round;
$_SESSION[draw_rotate] = $deg;
$_SESSION[draw_skew_x] = $skewX;
$_SESSION[draw_skew_y] = $skewY;
header("Location: display.php");
exit;
} ################### End ##################
if ( $_GET[poly_image_x] && $_GET[poly_image_y] )
{
$x = $_GET[poly_image_x];
$y = $_GET[poly_image_y];
$poly_path = "$_GET[coorids] $x,$y";
$_SESSION[poly_path] ="$poly_path";
header("Location: $self"); exit;
}
?>
include("style.txt"); ?>
echo "$h1: $h2"; ?>
=$h1; ?>
include("nav.php"); ?>
=$h2; ?>
if ( $_SESSION[error] )
{
echo "$_SESSION[error]";
$_SESSION[error] = NULL;
}
?>
if ( !isset($_SESSION[path]) )
{
echo "";
echo "No image";
echo "
";
}
if ( isset($_SESSION[path]) )
{
echo "";
}
?>
Instructions
- Click where you want a point. Continue until you have three or more points
or
Enter the x,y cooridinates of points separated by spaces. Do not use line breaks Example:
100,10 10,100, 150,10
- Enter Stroke Color. Can be valid color name or hex.
- Enter Stroke Width. (optional)
- Select Line Cap style. (optional)
- Enter Fill Color. Can be valid color name or hex.(optional).
- Enter Stroke Opacity. Range: 0-1 (optional)
- Enter Stroke Alpha. Range: 0-1 (optional)
- Enter Fill Opacity. Range: 0-1 (optional)
- Enter Fill Alpha. Range: 0-1 (optional)
- Click Polygon.or Polyline
- Your settings (except for cooridinates) will be saved. Clicking Reset will delete your settings
- Bezier
- A smooth curve defined by two end points and a series of control points between them that effect the shape of the curve.
- Polygons
- Polygons are a closed shape defined by its corner points
- Polylines
- Polygons are an open shape defined by its corner points
- Fill Color
- The color Inside the ellipse
- Stroke Color
- The color of the lines
- Stroke Width
- The thickness of the lines
- Line Cap
- How the lines end.
- Stroke Alpha
- Transparency of lines
- Fill Alpha
- Transparency of fill
- Fill Opacity
- Rotate
- Rotate draw object
- Skew
- Skews the shape. Enter degrees of skew.
- Scale
- Stretch the shape. 1 for unchanged. 2 to double etc
/*
*/
?>
include("footer.php");
?>