<?php
define ( 'IMAGE_FLIP_HORIZONTAL', 1 );
define ( 'IMAGE_FLIP_VERTICAL', 2 );
define ( 'IMAGE_FLIP_BOTH', 3 );
$main_file = $_GET["file"];
$imgImport = imagecreatefromjpeg($main_file);
$imgName_w = imagesx($imgImport);
$imgName_h = imagesy($imgImport);
// How many pixels to add to the left and right
$expand = 30;
// How deep to make it
$depth = 30;
// Transparency level to start from
$transparencyFrom = 80;
// Transparency level to end up with
$transparencyTo = 0;
$newImage = imagecreatetruecolor($imgName_w + $expand*2, $imgName_h + $depth);
$gdGradientColor=ImageColorAllocate($newImage,255,255,255);
imagefilledrectangle($newImage,0,0,$imgName_w + $expand*2,
$imgName_h + $depth, $gdGradientColor);
imagecopymerge($newImage, $imgImport, $expand, 0, 0, 0,
$imgName_w, $imgName_h, 100);
$flippedImage = ImageFlip( $imgImport, IMAGE_FLIP_HORIZONTAL );
$iter = $expand / $depth;
$tmpImage = imagecreatetruecolor($imgName_w + $expand*2, 1);
$transparencyIterations = ($transparencyFrom - $transparencyTo) / $depth;
$expanding = $expand ;
for ($y = 0; $y < $depth; $y++)
{
imagefilledrectangle($tmpImage,0,0,$imgName_w + $expand*2,1, $gdGradientColor);
imagecopyresized( $tmpImage ,$flippedImage, $expanding, 0, 0, $y ,
$imgName_w+(($expand-$expanding)*2),1, $imgName_w,1 );
imagecopymerge($newImage,$tmpImage,0,$y + $imgName_h,
0,0,$imgName_w + $expand*2, 1,$transparencyFrom);
$transparencyFrom -= $transparencyIterations;
$expanding -= $iter;
}
imagecopyresampled($imgImport,$newImage, 0, 0, 0, 0 ,$imgName_w,$imgName_h,
$imgName_w + $expand*2, $imgName_h + $depth );
header("Content-type: image/jpeg");
imagejpeg($imgImport, '', 80); //100 being the quality of image 100 Max(Best)
imagedestroy($newImage);
imagedestroy($tmpImage);
imagedestroy($flippedImage);
imagedestroy($imgImport);
// Image flip - not my code, from the PHP examples
function ImageFlip ( $imgsrc, $mode )
{
$width = imagesx ( $imgsrc );
$height = imagesy ( $imgsrc );
$src_x = 0;
$src_y = 0;
$src_width = $width;
$src_height = $height;
switch ( (int) $mode )
{
case IMAGE_FLIP_HORIZONTAL:
$src_y = $height-1;
$src_height = -$height;
break;
case IMAGE_FLIP_VERTICAL:
$src_x = $width;
$src_width = -$width;
break;
case IMAGE_FLIP_BOTH:
$src_x = $width;
$src_y = $height;
$src_width = -$width;
$src_height = -$height;
break;
default:
return $imgsrc;
}
$imgdest = imagecreatetruecolor ( $width, $height );
if ( imagecopyresampled ( $imgdest, $imgsrc, 0, 0, $src_x, $src_y,
$width, $height, $src_width, $src_height ) )
{
return $imgdest;
}
return $imgsrc;
}
?>