$img = imagecreatefromjpeg( $srcFile );
list($w, $h) = getimagesize( $srcFile );
$ha1 = imagettfbbox($headerSize, 0, $font1, $header );
$ha2 = imagettfbbox($textSize, 0,$font, $text );
$wt1 = $ha1[2]-$ha1[0];
$ht1 = $ha1[1]-$ha1[7];
$wt2 = $ha2[2]-$ha2[0];
$ht2 = $ha2[1]-$ha2[7];
$fw = $w + 8 + $imageMargin * 2 + $borderPad * 2;
$fh = $h + 8 + $imageMargin * 2 + $borderPad * 2 + $ht1 + $ht2 + $spacing * 3;
$fon = imagecreatetruecolor($fw, $fh);
$white = imagecolorallocate( $fon, 255, 255, 255 );
$black = imagecolorallocate( $fon, 97, 161, 23 );
imagefill( $fon, 0, 0, $black );
imagecopy( $fon, $img, $imageMargin + $borderPad + 4, $imageMargin + $borderPad + 4, 0, 0, $w, $h );
imagerectangle( $fon, $imageMargin + $borderPad + 4 - 3, $imageMargin + $borderPad + 4 - 3,
$imageMargin + $borderPad + $w + 4 + 2, $imageMargin + $borderPad + $h + 4 + 2, $white );
imagerectangle( $fon, $imageMargin + $borderPad + 4 - 4, $imageMargin + $borderPad + 4 - 4,
$imageMargin + $borderPad + $w + 4 + 3, $imageMargin + $borderPad + $h + 4 + 3, $white );
imagettftext( $fon, $headerSize, 0,
($fw - $wt1) / 2, $imageMargin + $borderPad*2 + 8 + $h + $ht1 + $spacing,
$white, $font1, $header );
imagettftext( $fon, $textSize, 0,
($fw - $wt2) / 2, $imageMargin + $borderPad*2 + 8 + $h + $ht1 + $ht2 + $spacing*2,
$white, $font, $text );
$ts=$dirdem.time();
$ts1='/uploads/demotivation/'.time();
imagejpeg( $fon, $ts."_foto.jpg", 98 );
imagecolordeallocate( $fon, $black );
imagecolordeallocate( $fon, $white );
imagedestroy( $fon );