<?php
//this is the core function.
function create_pic($id,$text,$url){
$img = $_POST["image"];
$image = "visuels/".$img.".png";
// creation of a new image, the final one
$im = imagecreatetruecolor(500,500);
// importing profile picture
$profile = imagecreatefromjpeg($url);
// importing transparent mirror image
$mirror = imagecreatefrompng($image);
//end function getJPEGresolution
// retrieving profile picture size
$sizes = getimagesize($url);
$x_dim = $sizes[0];
$y_dim = $sizes[1];
// mirror transparency is 265x335, so I resize the profile picture
// to fit this size, keeping widht/height ratio
if($x_dim<150 or $y_dim<170){
$mult = max(150/$x_dim,170/$y_dim);
$final_x = $x_dim*$mult;
$final_y = $y_dim*$mult;
}
// pasting the resized profile picture on the final image
imagecopyresampled($im,$profile,250-$final_x/2,240-$final_y/2,0,0,$final_x,$final_y,$x_dim,$y_dim);
// pasting the mirror on the final image
imagecopyresampled($im,$mirror,0,0,0,0,500,500,500,500);
// creating some colors
$color = imagecolorallocate($im, 207, 0, 75);
$shadow = imagecolorallocate($im, 0, 0, 0);
// this is the path of the font I am using
$font = "visuels/font.ttf";
// starting at font size 0
$size = 0;
// boolean variable to determine if the font fits on the picture
$it_fits = true;
// increasing font zize by one unit until it won't fit anymore
do{
$last_dim = $dim;
$size++;
$dim = imageftbbox($size, 0, $font, $text);
if($dim[4]-$dim[6]>300){
$it_fits=false;
}
} while($it_fits);
$center = floor((500-$last_dim[4]+$last_dim[6])/2);
imagettftext($im, $size-1, 0, $center, 100, $shadow, $font, $text);
imagettftext($im, $size-1, 0, $center-1, 100-1, $color, $font, $text);
imagejpeg($im,"temp/".$id.".jpg",100);
header('Content-type:image/jpeg');
imagedestroy($im);
imagedestroy($profile);
imagedestroy($mirror);
}
?>
<?php
// core function: creation of the horror picture
create_pic($uid,$text,$user_image);