<?php
function line_width($bounding_box) {
return abs($bounding_box[2] - $bounding_box[0]);
}
function line_height($bounding_box) {
return abs($bounding_box[1] - $bounding_box[5]);
}
function write_line($image, $size, $x, $y, $color, $font, $text) {
$bbox = imagettfbbox($size, 0.0, $font, $text);
$width = line_width($bbox);
$height = line_height($bbox);
if ($x == 'LEFT') {
$x = 0;
} else if ($x == 'CENTER') {
$x = (imagesx($image) - $width) / 2.0;
} else if ($x == 'RIGHT') {
$x = imagesx($image) - $width;
}
imagettftext($image, $size, 0.0, $x, $y + $height, $color, $font, $text);
return $bbox;
}
function write_lines($image, $size, $x, $y, $color, $font, $text, $padding = 0) {
foreach ($text as $line) {
$bbox = write_line($image, $size, $x, $y, $color, $font, $line);
$y += line_height($bbox) + $padding;
}
}
header('Content-type: image/png');
$nome = $_POST['nome'];
$grado = $_POST['grado'];
$officiante = $_POST['officiante'];
$diocesi = $_POST['diofun'];
$arcidiocesi = $_POST['arcifun'];
$data = $_POST['datafun'];
$image = imagecreatefromjpeg("http://i.imgur.com/vOZBXEo.jpg");
$color = imagecolorallocate($image, 0x8B, 0x00, 0x00);
$text = array(
"Il fedele dell'Altissimo chiamato",
$nome,
"dopo la prematura morte,",
"ha ricevuto il sacramento del funerale,",
"dal $grado$officiante",
"nella Parrocchia di $diocesi, Arcidiocesi di $arcidiocesi,",
"in data $data"
);
write_lines($image, 14, 'CENTER', 350, $color, "http://www.princexml.com/fonts/larabie/kimberle.ttf", $text, 5);
imagepng($image);