error_reporting(0);
include("functions.php");
$h1 = "DJ Mike's Image Maker 2";
$h2 = "Distort";
##### Start Distort
if ( $_SESSION[path] && $_GET[distort] )
{
$distort_params = trim($_GET[distort_params]);
$distort_params = strip_tags($distort_params);
$array = explode( ",", "$distort_params" );
foreach( $array as $temp )
{
$temp = trim($temp);
$temp = (float)$temp;
$args[] = $temp;
}
## validate color ##
if ( !$_GET[distort_bg] )
{ $distort_bg = "transparent"; }
else
{
$distort_bg = trim($_GET[distort_bg] );
$distort_bg = colors( $distort_bg, "validate" );
if ( !$distort_bg )
{
$_SESSION[error] = "Color is invalid";
header("location:$self");
exit;
}
}
$image = new Imagick($_SESSION[path]);
foreach ($image as $frame) # start frame loop
{
# add border to avoid streaks
$frame->borderImage( "$distort_bg", 1, 1 );
#### PerspectiveProjection ###
if ( $_GET[distort] == "PerspectiveProjection" )
{
# user may enter garbage so use exception to test
try {
$image->distortimage(
imagick::DISTORTION_PERSPECTIVEPROJECTION,
$args,
TRUE);
}
catch ( exception $e )
{ $_SESSION[error] = "Invalid input for selected distort method
";
header("location:$self");
exit; }
}
#### end PerspectiveProjection
#### AffineProjection ###
if ( $_GET[distort] == "AffineProjection" )
{
# user may enter garbage so use exception to test
try {
$image->distortimage(
imagick::DISTORTION_AFFINEPROJECTION,
$args,
TRUE);
}
catch ( exception $e )
{ $_SESSION[error] = "Invalid input for selected distort method
";
header("location:$self");
exit; }
}
#### end AffineProjection
#### Affine ###
if ( $_GET[distort] == "Affine" )
{
# user may enter garbage so use exception to test
try {
$image->distortimage(
imagick::DISTORTION_AFFINE,
$args,
TRUE);
}
catch ( exception $e )
{ $_SESSION[error] = "Invalid input for selected distort method
";
header("location:$self");
exit; }
}
#### end Affine
#### SRT ###
if ( $_GET[distort] == "SRT" )
{
# user may enter garbage so use exception to test
try {
$image->distortimage(
imagick::DISTORTION_SCALEROTATETRANSLATE,
$args,
TRUE);
}
catch ( exception $e )
{ $_SESSION[error] = "Invalid input for selected distort method
";
header("location:$self");
exit; }
}
#### end SRT
#### ARC ###
if ( $_GET[distort] == "Arc" )
{
# user may enter garbage so use exception to test
try {
$image->distortimage( imagick::DISTORTION_ARC, $args, TRUE);
}
catch ( exception $e )
{ $_SESSION[error] = "Invalid input for selected distort method
";
header("location:$self");
exit; }
}
#### end Arc
#### Perspective ####
if ( $_GET[distort] == "Perspective" )
{
# user may enter garbage so use exception to test
try {
$image->distortimage( imagick::DISTORTION_PERSPECTIVE, $args, TRUE);
}
catch ( exception $e )
{ $_SESSION[error] = "Invalid input for selected distort method
";
header("location:$self");
exit; }
}
#### end Perspective
#### Bilinear ####
if ( $_GET[distort] == "Bilinear" )
{
# user may enter garbage so use exception to test
try {
$image->distortimage( imagick::DISTORTION_BILINEAR, $args, TRUE);
}
catch ( exception $e )
{ $_SESSION[error] = "Invalid input for selected distort method
";
header("location:$self");
exit; }
}
#### end Bilinear
#### Undefined ####
if ( $_GET[distort] == "Undefined" )
{
# user may enter garbage so use exception to test
try {
$image->distortimage( imagick::DISTORTION_UNDEFINED, $args, TRUE);
}
catch ( exception $e )
{ $_SESSION[error] = "Invalid input for selected distort method
";
header("location:$self");
exit; }
}
#### end Undefined
# remove border that you added above.
$frame->shaveImage(1,1);
} # end frame loop
$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[distort_params] = $distort_params;
$_SESSION[distort_bg] = $distort_bg;
$_SESSION[path] = $path;
header("Location: display.php");
exit;
}
######### end Distort
include("top.php");
?>
Distort an image. Enter arguments separated by commas. You can use spaces and line breaks to make your input easier to read.
This works a little differently than Imagemagick. Instead of using a virtual pixel method it uses a background color. If you don't enter a background color it defaults to transparent for GIF's and PNG's, black for JPG's
X1s,Y1s,
X1e,Y1e,
X2s,Y2s,
X2e,Y2e,
X3s,Y3s,
X3e,Y3e,
X4s,Y4s, X4e,Y4e