// Get your Text Width and Height
$text_width = $text_box[2]-$text_box[0];
$text_height = $text_box[7]-$text_box[1];
// Calculate coordinates of the text
$x = ($image_width/2) - ($text_width/2);
$y = ($image_height/2) - ($text_height/2);
$lines = explode('|', wordwrap($text, 75, '|'));
// Starting Y position
$y = 150;
// Loop through the lines and place them on the image
foreach ($lines as $line)
{
$text_box = imagettfbbox($font_size,$angle,$font,$text);
imagettftext($image, $font_size, 0, $x, $y, $couleurTxt, $font, $line);
// Increment Y so the next line is below the previous line
$y += 50;
}
Et pour le coup l'image ne s'affiche plus du tout ...
$lines = explode('|', wordwrap($text, 75, '|'));
// Starting Y position
$y = 150;
// Loop through the lines and place them on the image
foreach ($lines as $line)
{
$text_box = imagettfbbox($font_size,$angle,$font,$text);
// Get your Text Width and Height
$text_width = $text_box[2]-$text_box[0];
$text_height = $text_box[7]-$text_box[1];
// Calculate coordinates of the text
$x = ($image_width/2) - ($text_width/2);
$y = ($image_height/2) - ($text_height/2);
imagettftext($image, $font_size, 0, $x, $y, $couleurTxt, $font, $line);
// Increment Y so the next line is below the previous line
$y += 50;
}[/php$lines = explode('|', wordwrap($text, 75, '|'));
// Starting Y position
$y = 150;
// Loop through the lines and place them on the image
foreach ($lines as $line)
{
$text_box = imagettfbbox($font_size,$angle,$font,$text);
// Get your Text Width and Height
$text_width = $text_box[2]-$text_box[0];
$text_height = $text_box[7]-$text_box[1];
// Calculate coordinates of the text
$x = ($image_width/2) - ($text_width/2);
if (empty($y)) {$y = ($image_height/2) - ($text_height/2);}//ya un truc à faire avec Y pour qu'il soit à la bonne valeur à chaque itération
imagettftext($image, $font_size, 0, $x, $y, $couleurTxt, $font, $line);
// Increment Y so the next line is below the previous line
$y += 50;
}require('gif.class.php');
$animation = array();
$duree = array();
//define('LARGEUR', 600);
//define('HAUTEUR', 600);
/* * ******************************* * Parametre * ******************************** */
$largeur = 600; /* longueur de l'image */
$hauteur = 600; /* hauteur de l'image */
$txt = str_replace ("vœux", "voeux", $_GET['fichier']);
$txt = rawurlencode($txt);
$txt = str_replace('%92', '%27', $txt);
$txt = rawurldecode($txt);
/* * ******************************* * IMAGE 1 * ******************************** */
$image = imagecreate($largeur, $hauteur);
/* Background */
$background = imagecolorallocate($image, 0, 255, 0);
$image= imagecreatefrompng('carte_voeux_2016/1.png'); //Notre joli fond :p
/* Couleur du text */
if($_GET['couleur'] =='blanc') {
$couleurTxt = imagecolorallocate($image, 255, 255, 255);
} else {
$couleurTxt = imagecolorallocate($image, 19, 57, 92);
}
/* texte à mettre dans l'image */
/* Taille du texte */
$font_size = 10;
putenv('GDFONTPATH=' . realpath('.'));
$font = 'arial.ttf';
/* Hauteur et largeur des caratères */
$largeurCaractere = ImageFontWidth($font_size);
$hauteurCaractere = ImageFontHeight($font_size);
/* Longueur du texte (taille caratère X nombre de caractère) */
$largeurTxt = $largeurCaractere * strlen($txt);
/* Recherche de la position horizontale centrale pour centrer le texte */
$positionCentreHor = ceil(($largeur - $largeurTxt) / 2);
/* Recherche de la position horizontale centrale pour centrer le texte */
//$positionCentreVer = ceil(($hauteur - $hauteurCaractere) / 2);
$positionCentreVer = 160;
/* Ajout du texte au centre de l'image */
$angle = 0;
$text_length = 90;
$new_text = wordwrap($txt, $text_length, "<br />", true);
// Calculate coordinates of the text
$x = ($image_width/2) - ($text_width/2);
$y = ($image_height/2) - ($text_height/2);
$lines = explode('|', wordwrap($text, 75, '|'));
// Starting Y position
$y = 150;
// Loop through the lines and place them on the image
foreach ($lines as $line)
{
$text_box = imagettfbbox($font_size,$angle,$font,$text);
// Get your Text Width and Height
$text_width = $text_box[2]-$text_box[0];
$text_height = $text_box[7]-$text_box[1];
// Calculate coordinates of the text
$x = ($image_width/2) - ($text_width/2);
if (empty($y)) {$y = ($image_height/2) - ($text_height/2);}//ya un truc à faire avec Y pour qu'il soit à la bonne valeur à chaque itération
imagettftext($image, $font_size, 0, $x, $y, $couleurTxt, $font, $line);
// Increment Y so the next line is below the previous line
$y += 50;
}
ob_start();
imagegif($image);
$animation[] = ob_get_clean();
$duree[] = 35;
imagedestroy($image);
/* */
/* * ******************************* * CREATION IMAGE * ******************************** */
$gif = new GIFEncoder($animation, $duree, 0, 2, 0, 0, 0, 'bin');
header ("Content-type: image/gif");
echo $gif->GetAnimation();<?php
require('gif.class.php');
$animation = array();
$duree = array();
//define('LARGEUR', 600);
//define('HAUTEUR', 600);
/* * ******************************* * Parametre * ******************************** */
$largeur = 600; /* longueur de l'image */
$hauteur = 600; /* hauteur de l'image */
$txt = str_replace ("vœux", "voeux", $_GET['fichier']);
$txt = rawurlencode($txt);
$txt = str_replace('%92', '%27', $txt);
$txt = rawurldecode($txt);
/* * ******************************* * IMAGE 1 * ******************************** */
$image = imagecreate($largeur, $hauteur);
/* Background */
$background = imagecolorallocate($image, 0, 255, 0);
$image= imagecreatefrompng('carte_voeux_2016/1.png'); //Notre joli fond :p
/* Couleur du text */
if($_GET['couleur'] =='blanc') {
$couleurTxt = imagecolorallocate($image, 255, 255, 255);
} else {
$couleurTxt = imagecolorallocate($image, 19, 57, 92);
}
/* texte à mettre dans l'image */
/* Taille du texte */
$font_size = 10;
putenv('GDFONTPATH=' . realpath('.'));
$font = 'arial.ttf';
/* Hauteur et largeur des caratères */
$largeurCaractere = ImageFontWidth($font_size);
$hauteurCaractere = ImageFontHeight($font_size);
/* Longueur du texte (taille caratère X nombre de caractère) */
$largeurTxt = $largeurCaractere * strlen($txt);
/* Recherche de la position horizontale centrale pour centrer le texte */
$positionCentreHor = ceil(($largeur - $largeurTxt) / 2);
/* Recherche de la position horizontale centrale pour centrer le texte */
//$positionCentreVer = ceil(($hauteur - $hauteurCaractere) / 2);
$positionCentreVer = 160;
/* Ajout du texte au centre de l'image */
$angle = 0;
$text_length = 90;
$new_text = wordwrap($txt, $text_length, "<br />", true);
$text = str_replace('<br />', "\n", $new_text);
$lines = explode('|', wordwrap($text, 75, '|'));
$y = 150;
// Loop through the lines and place them on the image
foreach ($lines as $line)
{
$text_box = imagettfbbox($font_size,$angle,$font,$line);
// Get your Text Width and Height
$text_width = $text_box[2]-$text_box[0];
$text_height = $text_box[7]-$text_box[1];
// Calculate coordinates of the text
$x = ($largeur/2) - ($text_width/2);
if (empty($y)) {$y = ($hauteur/2) - ($text_height/2);}//ya un truc à faire avec Y pour qu'il soit à la bonne valeur à chaque itération
imagettftext($image, $font_size, 0, $x, $y, $couleurTxt, $font, $line);
// Increment Y so the next line is below the previous line
$y += 50;
}
ob_start();
imagegif($image);
$animation[] = ob_get_clean();
$duree[] = 35;
imagedestroy($image);
/* */
/* * ******************************* * CREATION IMAGE * ******************************** */
$gif = new GIFEncoder($animation, $duree, 0, 2, 0, 0, 0, 'bin');
header ("Content-type: image/gif");
echo $gif->GetAnimation();
?>