error_reporting(0);
include("functions.php");
$h1 = "DJ Mike's Image Maker 2";
$h2 = "Lines, Circles And Rectangles";
##
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;
header("location:$self");
exit;
}
# 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;
if ( $_GET[ul_x] &&
$_GET[ul_y] &&
$_GET[lr_x] &&
$_GET[lr_y] &&
$_GET[action] )
{
$ul_x = (int)$_GET[ul_x];
$ul_y = (int)$_GET[ul_y];
$lr_x = (int)$_GET[lr_x];
$lr_y = (int)$_GET[lr_y];
$x_round = (float)$_GET[x_round];
$y_round = (float)$_GET[y_round];
# set colors
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->setstrokeopacity($stroke_opacity); }
if ( $fill_opacity ) { $draw->setfillopacity($fill_opacity); }
if ( $fill_alpha ) { $draw->setfillalpha($fill_alpha); }
# 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);
##### draw Round Rectangle ####
if ( $_GET[action] == "Round Rectangle" )
{
$draw->roundrectangle( $ul_x, $ul_y,
$lr_x, $lr_y,
$x_round, $y_round);
foreach ($image as $frame) { $frame->drawimage($draw); }
}
############################
########## draw circle #########
if ( $_GET[action] == "Circle" )
{
$draw->circle( $ul_x,$ul_y, $lr_x, $lr_y);
foreach ($image as $frame) { $frame->drawimage($draw); }
}
############################
########## draw line #########
if ( $_GET[action] == "Line" )
{
$draw->line( $ul_x,$ul_y, $lr_x, $lr_y);
foreach ($image as $frame) { $frame->drawimage($draw); }
}
############################
####### draw rectangle ########
if ( $_GET[action] == "Rectangle" )
{
$draw->rectangle( $ul_x,$ul_y, $lr_x, $lr_y);
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[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;
header("Location: display.php");
exit;
# end draw
}
############ step 2
# if 2nd coorids not set, set var for form
if ( $_GET[crop_image_x] && $_GET[crop_image_y] &&
$_GET[ul_x] && $_GET[ul_y] &&
!$_GET[lr_x] && !$_GET[lr_y]
)
{
$ul_x = $_GET[ul_x];
$ul_y = $_GET[ul_y];
$lr_x = $_GET[crop_image_x];
$lr_y = $_GET[crop_image_y];
header("location:$self?ul_x=$ul_x&ul_y=$ul_y&lr_x=$lr_x&lr_y=$lr_y");
exit;
}
# Step 1.
# Vars shouldn't be set at this point
# if 1st coorids not set, set vars for form
if ($_GET[crop_image_x] && $_GET[crop_image_y] &&
!$_GET[ul_x] &&
!$_GET[ul_x] &&
!$_GET[lr_x] &&
!$_GET[lr_x]
)
{
$ul_x = $_GET[crop_image_x];
$ul_y = $_GET[crop_image_y];
header("location:$self?ul_x=$ul_x&ul_y=$ul_y");
exit;
}
?>
| Point 1 | Point 2 | ||
|
|
|||
| Fill Color | |||
| Stroke Color | |||
| Stroke Width | |||
| Stroke Opacity | Stroke Alpha | ||
| Fill Opacity | Fill Alpha | ||
| X-Round | Y-Round | ||