PHP Code:
<?php
header ('Content-Type: image/png');
$file = 'images/baselayer.png';
list($imagewidth, $imageheight) = getimagesize($file);
$image = imagecreatefrompng($file);
$setwidth = 225;
$setheight = 230;
$filename = $_REQUEST['image1'];
list($width, $height) = getimagesize($filename);
if ($width == $height) { $height = $height + 1; }
if ($width < $height && $setwidth < $setheight) { $case = "1"; }
if ($width > $height && $setwidth > $setheight) { $case = "2"; }
if ($width < $height && $setwidth > $setheight) { $case = "3"; }
if ($width > $height && $setwidth < $setheight) { $case = "4"; }
if ($width == $setwidth && $height == $setheight) { $case == "5"; }
switch ($case) {
case "1" : $rqst_pro = $setheight / $setwidth; $orig_pro = $height / $width; if ($orig_pro > $rqst_pro) { $dst_w = $setwidth; $dst_h = round(($dst_w / $width) * $height); $dst_y = (($setheight - $dst_h) / 2); } else { $dst_h = $setheight; $dst_w = round(($dst_h / $height) * $width); $dst_y = (($setheight - $dst_h) / 2); }
break;
case "2" : $rqst_pro = $setwidth / $setheight; $orig_pro = $width / $height; if ($orig_pro < $rqst_pro) { $dst_w = $setwidth; $dst_h = round(($dst_w / $width) * $height); $dst_x = (($setwidth - $dst_w) / 2); } else { $dst_h = $setheight; $dst_w = round(($dst_h / $height) * $width); $dst_x = (($setwidth - $dst_w) / 2); }
break;
case "3" : $dst_w = $setwidth; $dst_h = round(($dst_w / $width) * $height); $dst_y = (($setheight - $dst_h) / 2);
break;
case "4" : $dst_h = $setheight; $dst_w = round(($dst_h / $height) * $width); $dst_x = (($setwidth - $dst_w) / 2);
break;
case "5" : $dst_h = $setheight; $dst_w = $setwidth;
break;
}
$filename2 = $_REQUEST['image2'];
list($width2, $height2) = getimagesize($filename2);
if ($width2 == $height2) { $height2 = $height2 + 1; }
if ($width2 < $height2 && $setwidth < $setheight) { $case2 = "1"; }
if ($width2 > $height2 && $setwidth > $setheight) { $case2 = "2"; }
if ($width2 < $height2 && $setwidth > $setheight) { $case2 = "3"; }
if ($width2 > $height2 && $setwidth < $setheight) { $case2 = "4"; }
if ($width2 == $setwidth && $height == $setheight) { $case2 == "5"; }
switch ($case2) {
case "1" : $rqst_pro2 = $setheight / $setwidth; $orig_pro2 = $height2 / $width2; if ($orig_pro2 > $rqst_pro2) { $dst_w2 = $setwidth; $dst_h2 = round(($dst_w2 / $width2) * $height2); $dst_y2 = (($setheight - $dst_h2) / 2); } else { $dst_h2 = $setheight; $dst_w2 = round(($dst_h2 / $height2) * $width2); $dst_y2 = (($setheight - $dst_h2) / 2); }
break;
case "2" : $rqst_pro2 = $setwidth / $setheight; $orig_pro2 = $width2 / $height2; if ($orig_pro2 < $rqst_pro2) { $dst_w2 = $setwidth; $dst_h2 = round(($dst_w2 / $width2) * $height2); $dst_x2 = (($setwidth - $dst_w2) / 2); } else { $dst_h2 = $setheight; $dst_w2 = round(($dst_h2 / $height2) * $width2); $dst_x2 = (($setwidth - $dst_w2) / 2); }
break;
case "3" : $dst_w2 = $setwidth; $dst_h2 = round(($dst_w2 / $width2) * $height2); $dst_y2 = (($setheight - $dst_h2) / 2);
break;
case "4" : $dst_h2 = $setheight; $dst_w2 = round(($dst_h2 / $height2) * $width2); $dst_x2 = (($setwidth - $dst_w2) / 2);
break;
case "5" : $dst_h2 = $setheight; $dst_w2 = $setwidth;
break;
}
$dst_image = imagecreatetruecolor($setwidth, $setheight);
$src_image = imagecreatefromjpeg($filename);
imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $width, $height );
$degrees = 7;
$rotate = imagerotate($dst_image, $degrees, -1);
$dst_image2 = imagecreatetruecolor($setwidth, $setheight);
$src_image2 = imagecreatefromjpeg($filename2);
imagecopyresampled ($dst_image2, $src_image2, $dst_x2, $dst_y2, 0, 0, $dst_w2, $dst_h2, $width2, $height2 );
$degrees2 = -7;
$rotate2 = imagerotate($dst_image2, $degrees2, -1);
imagecopy($image, $rotate, 40, 25, 0, 0, 240, 220);
imagecopy($image, $rotate2, 280, 40, 0, 0, 240, 220);
// define the sharpen matrix
$sharpen = array(
array(0.0, -1.0, 0.0),
array(-1.0, 5.0, -1.0),
array(0.0, -1.0, 0.0)
);
// calculate the sharpen divisor
$divisor = array_sum(array_map('array_sum', $sharpen));
// apply the matrix
imageconvolution($image, $sharpen, $divisor, 0);
$watermark = imagecreatefrompng("images/toplayer.png");
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
imagecopy($image, $watermark, 0, 0, 0, 0, $watermark_width, $watermark_height);
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
Bookmarks