error_reporting(0);
include("functions.php");
include("fonts.php");
$h1 = "DJ Mike's Image Maker 2";
$h2 = "Annotate";
#########################
# Sweep font directory every time this page viewed
### Directory Sweeper ###
# create directory resource and read it
$directory = opendir("temp_fonts/");
while (true == ($file = readdir($directory)))
{
# but don't read the links to directories
if ( is_file("temp_fonts/$file") )
{
# find out when it was created
$created_time = filemtime("temp_fonts/$file");
# $age = present time-$created_time
$age = time()-filemtime("temp_fonts/$file");
# delete if more than 8 hours old.
# 8 hr = 28800 seconds; 24 hr= 86400 sec
# don't delete the indexes or .htaccess or fonts
if ( $age > 28800 && !preg_match("@\.htaccess|index\.ttf@i", $file, $x) )
{ unlink("temp_fonts/$file"); }
# sweeps out any files that don't belong
if ( !preg_match("@(.htaccess|index|\.ttf)$@i", $file, $x) )
{ unlink("temp_fonts/$file"); }
}
}
closedir($directory);
################################## End Sweeper
# is font submitted?
if ( $new_font = trim($_GET[new_font]) )
{
# does font start with http:// and end in .ttf?
if ( preg_match( "@^http://.*\.ttf$@i", "$new_font", $match ) )
{
# get file name
$name = explode( "/", $new_font );
$name = array_pop($name);
# replace invalid characters
$name = preg_replace( "@[^\w\.]@i", "_", $name);
# try to copy font
if ( @copy( $new_font, "temp_fonts/$name") )
{
$_SESSION[sucess] = "$name has been uploaded";
header("location:$self"); exit;
}
else
{
$_SESSION[error] = "Could not upload $new_font";
header("location:$self"); exit;
}
}
else
{
$_SESSION[error] = "$new_font is not a font.";
header("location:$self"); exit;
}
}
########### Annotete ##########
if ($_GET[annotate] && $_SESSION[path] )
{
$image = new Imagick($_SESSION[path]);
$draw = new imagickdraw();
$font = $_GET[font];
## vaidate font
try { $draw->setfont("$font"); }
catch ( exception $e )
{ $error .= "Select a font"; }
## validate font color ##
$font_color = trim($_GET[font_color] );
$font_color = colors( $font_color, "validate" );
if ( !$font_color )
{ $error .= "Font Color is invalid
"; }
## validate stroke color ##
$stroke_color = trim($_GET[anno_stroke_color] );
$stroke_color = colors( $stroke_color, "validate" );
if ( !$stroke_color )
{ $error .= "Stroke Color is invalid
"; }
if ( $under_color = trim($_GET[under_color]) )
{ $under_color = colors( $under_color, "validate" );}
if ( !$under_color )
{ $under_color = "none"; }
/*
# debug
echo "uc = $_GET[under_color]"; exit;
*/
## validate font size##
$font_size = $_GET[font_size];
if ( $font_size < 1)
{ $error .= "Enter a font size
"; }
if ( $error )
{
$_SESSION[error] .= "$error";
header("location:$self");
exit;
}
$anno_text = stripslashes($_GET[anno_text] );
$anno_off_x = (float)$_GET[anno_off_x];
$anno_off_y = (float)$_GET[anno_off_y];
$stroke_width = (int)$_GET[anno_stroke_width];
switch ( $_GET[anno_gravity] )
{
case "NORTHWEST" :
$gravity = imagick::GRAVITY_NORTHWEST;
break;
case "NORTH" :
$gravity = imagick::GRAVITY_NORTH;
break;
case "NORTHEAST" :
$gravity = imagick::GRAVITY_NORTHEAST;
break;
case "WEST" :
$gravity = imagick::GRAVITY_WEST;
break;
case "EAST" :
$gravity = imagick::GRAVITY_EAST;
break;
case "SOUTHWEST" :
$gravity = imagick::GRAVITY_SOUTHWEST;
break;
case "SOUTH" :
$gravity = imagick::GRAVITY_SOUTH;
break;
case "SOUTHEAST" :
$gravity = imagick::GRAVITY_SOUTHEAST;
break;
default :
$gravity = imagick::GRAVITY_CENTER;
}
#### set stroke alpha
if ($_GET[font_stroke_alpha])
{
$font_stroke_alpha = trim($_GET[font_stroke_alpha] );
$font_stroke_alpha = (float)$font_stroke_alpha;
if ( $font_stroke_alpha < 0 ) { $font_stroke_alpha = 0; }
if ( $font_stroke_alpha > 1 ) { $font_stroke_alpha = 1; }
}
#### set stroke opacity
if ($_GET[font_stroke_opacity])
{
$font_stroke_opacity = trim($_GET[font_stroke_opacity] );
$font_stroke_opacity = (float)$font_stroke_opacity;
if ( $font_stroke_opacity < 0 ) { $font_stroke_opacity = 0; }
if ( $font_stroke_opacity > 1 ) { $font_stroke_opacity = 1; }
}
#### set stroke fill opacity
if ($_GET[font_opacity])
{
$font_opacity = trim($_GET[font_opacity] );
$font_opacity = (float)$font_opacity;
if ( $font_opacity < 0 ) { $font_opacity = 0; }
if ( $font_opacity > 1 ) { $font_opacity = 1; }
}
#### set stroke fill alpha
if ($_GET[font_alpha])
{
$font_alpha = trim($_GET[font_alpha] );
$font_alpha = (float)$font_alpha;
if ( $font_alpha < 0 ) { $font_alpha = 0; }
if ( $font_alpha > 1 ) { $font_alpha = 1; }
}
$anno_deg = (float)$_GET[anno_deg];
# settings
$draw->setgravity($gravity);
$draw->setfillcolor($font_color);
$draw->setstrokecolor($stroke_color);
$draw->setfontsize($font_size);
$draw->setstrokewidth("$stroke_width");
$draw->rotate($anno_deg);
$draw->settextundercolor($under_color);
#### set stroke alpha/opacity & fill alpha/opacity
if ( $font_stroke_alpha )
{ $draw->setstrokealpha($font_stroke_alpha); }
if ( $font_stroke_opacity )
{ $draw->setstrokeopacity($font_stroke_opacity); }
if ( $font_opacity ) { $draw->setfillopacity($font_opacity); }
if ( $font_alpha ) { $draw->setfillalpha($font_alpha); }
#### Annotate each frame
foreach ($image as $frame)
{
$frame->annotateImage( $draw, $anno_off_x ,$anno_off_y, $anno_deg, $anno_text );
}
$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[path] = $path;
$_SESSION[anno_text] = $anno_text;
$_SESSION[anno_off_x] = $anno_off_x;
$_SESSION[anno_off_y] = $anno_off_y;
$_SESSION[font_color] = $font_color;
$_SESSION[anno_stroke_color] = $stroke_color;
$_SESSION[font_size] = $font_size;
$_SESSION[anno_stroke_width] = $stroke_width;
$_SESSION[font_opacity] = $font_opacity;
$_SESSION[font_alpha] = $font_alpha;
$_SESSION[font_stroke_opacity] = $font_stroke_opacity;
$_SESSION[font_stroke_alpha] = $font_stroke_alpha;
$_SESSION[anno_deg] = (float)$_GET[anno_deg];
$_SESSION[under_color] = $under_color;
header("location:display.php");
exit;
}
######### end Annotate #########
include("top.php");
if ($_SESSION[sucess] )
{
echo "