( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ
<?php
include('Connections/videoondemand.php');
$res = json_decode(stripslashes($_POST['jsondata']), true);
/* get data */
$count_images = count($res['images']);
/* the background image is the first one */
$background = $res['images'][0]['src'];
list($source_width, $source_height, $source_type) = getimagesize($background);
if ($source_type === NULL) {
return false;
}
switch ($source_type) {
case IMAGETYPE_GIF:
$photo1 = imagecreatefromgif($background);
break;
case IMAGETYPE_JPEG:
$photo1 = imagecreatefromjpeg($background);
break;
case IMAGETYPE_PNG:
$photo1 = imagecreatefrompng($background);
break;
default:
return false;
}
$foto1W = imagesx($photo1);
$foto1H = imagesy($photo1);
$photoFrameW = $res['images'][0]['width'];
$photoFrameH = $res['images'][0]['height'];
$photoFrame = imagecreatetruecolor($photoFrameW,$photoFrameH);
imagecopyresampled($photoFrame, $photo1, 0, 0, 0, 0, $photoFrameW, $photoFrameH, $foto1W, $foto1H);
/* the other images */
for($i = 1; $i < $count_images; ++$i){
$insert = $res['images'][$i]['src'];
$insert = str_replace("taswira.php?width=600&height=600&quality=100&cropratio=1:1&image=/","",$insert);
list($source_width, $source_height, $source_type) = getimagesize($insert);
if ($source_type === NULL) {
return false;
}
switch ($source_type) {
case IMAGETYPE_GIF:
$photo2 = imagecreatefromgif($insert);
break;
case IMAGETYPE_JPEG:
$photo2 = imagecreatefromjpeg($insert);;
break;
case IMAGETYPE_PNG:
$photo2 = imagecreatefrompng($insert);
break;
default:
return false;
}
$photoFrame2Rotation = (180-$res['images'][$i]['rotation']) + 180;
$foto2W = imagesx($photo2);
$foto2H = imagesy($photo2);
$photoFrame2W = $res['images'][$i]['width'];
$photoFrame2H = $res['images'][$i]['height'];
$photoFrame2TOP = $res['images'][$i]['top'];
$photoFrame2LEFT= $res['images'][$i]['left'];
$theImage = basename($insert);
$newsid = $_GET["pic"];
$basePic = basename($insert);
$query = mysqli_query("UPDATE elements SET foto2W = '$foto2W',foto2H = '$foto2H',photoFrame2W = '$photoFrame2W',photoFrame2H = '$photoFrame2H',photoFrame2TOP = '$photoFrame2TOP',photoFrame2LEFT = '$photoFrame2LEFT',photoFrame2Rotation = '$photoFrame2Rotation' WHERE picture = '$basePic' and pic = '$newsid'") or die(mysql_error());
$photoFrame2 = imagecreatetruecolor($photoFrame2W,$photoFrame2H);
$trans_colour = imagecolorallocatealpha($photoFrame2, 0, 0, 0, 127);
imagefill($photoFrame2, 0, 0, $trans_colour);
imagecopyresampled($photoFrame2, $photo2, 0, 0, 0, 0, $photoFrame2W, $photoFrame2H, $foto2W, $foto2H);
$photoFrame2 = imagerotate($photoFrame2,$photoFrame2Rotation, -1,0);
/*after rotating calculate the difference of new height/width with the one before*/
$extraTop =(imagesy($photoFrame2)-$photoFrame2H)/2;
$extraLeft =(imagesx($photoFrame2)-$photoFrame2W)/2;
imagecopy($photoFrame, $photoFrame2,$photoFrame2LEFT-$extraLeft, $photoFrame2TOP-$extraTop, 0, 0, imagesx($photoFrame2), imagesy($photoFrame2));
}
// Set the content type header - in this case image/jpeg
header('Content-type: image/jpeg');
imagejpeg($photoFrame, $targetfile,100);
imagedestroy($photoFrame);
?>