Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks > Images > GD
GD Forum d'entraide pour l'extension GD permettant de manipuler des images en PHP. Avant de poster -> tutoriels GD
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 28/03/2007, 20h28   #1
Nouveau Membre du Club
 
Inscription : mars 2007
Messages : 71
Détails du profil
Informations forums :
Inscription : mars 2007
Messages : 71
Points : 27
Points : 27
Par défaut Problème de création d'image avec GD2

Bonjour,
j' essaye de faire un petit script qui permettrait de générer des images avec du texte dessus qui serait mis forme lors de la création de l'image.
Seulement quand je veux l'executer il y a plein d'erreurs (je vois mon texte en haut de la page web et puis ensuite une page interminable de signes et lettres et chiffres .
Il y a deux pages (formulaire et page d'affichage) :

1ère page :
Code HTML :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<html>
<title>Bienvenue dans D&D QUID</title>
        <body>
<div align="center"><font face="Comic sans Ms" size="6" >
Remplissez les cases ci-dessous <br/>
afin de créer votre carte monstre :</font><br><br>
<form method = "post"  action= "carte.php"></div>
 
Nom du monstre :
<input type= "text" name= "Nom">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Jets de sauvegarde : 
  <input type= "text" name= "jets"><br>
  <br>
                             Taille :
<input type= "text" name= "taille">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Caractéristiques :
<input type= "text" name= "carac">
<br><br>
                     Dés de vie :
<input type= "text" name= "DV">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Compétences :
<input type="text" name="comp">
<br><br>
                        Initiative :
<input type="text" name="initiative">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dons : 
<input type="text" name="dons">
<br><br>
Vitesse de déplacement :
<input type="text" name="vitesse">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Milieu naturel/climat : 
<input type="text" name="milieu">
<br><br>
           Classe d'armure :
<input type="text" name="CA">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Organistation sociale : 
<input type="text" name="social">
<br><br>
                      Attaques :
<input type="text" name="attaques">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Facteur de puissance : 
<input type="text" name="facteur">
<br><br>
                         Dégâts :
<input type="text" name="degats">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Trésor :
<input type="text" name="tresor">
<br><br>
Espace occupé/allonge :
<input type="text" name="espace">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Alignement : 
<input type="text" name="alignement">
<br><br>
       Attaques spéciales :
<input type="text" name="aspe">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Puissance possible : 
<input type="text" name="puissance">
<br><br>
                Particularités :
<input type="text" name="particularites">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" value="Créer la carte !"> 
</form>
        </body>
</html>

la 2ème page :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
// Fonction pour déterminer le centrage de la chaine de caractères (elle prend comme paramètre : la chaine et la police d'écriture
function centrage_texte($z,$y)
{
// Je calcule le nombre de caractères dans la chaine
$a = strlen($z);
// Je calcule la taille d'un caractère par rapport à la taille de la police
$b = imagefontwidth($y);
// Je calcule la taille de ma chaine de caractères
$c = $a*$b;
// Je calcule combien il me reste de caractères/espace sur les côtés pour centrer mon texte
$d = 350-$c;
// Je recherche l'emplacement où débutera ma chaine de caractères
$e = $d/2;
// La chaine commencera ... à cet emplacement
return $e;
} 
//******************************************
//  Limite du nombre de caractères par ligne
//
//  nom fonction : CharParLigne($texte,$maxCar)
//   - $texte : texte a formater
//   - maxCar : Nb Maxi de Caracteres par ligne
//
 
function CharParLigne($texte,$maxCar){
 
  //explosion du texte en lignes
  $t_texte=explode("\n",$texte);
  $ret="";
 
  //Balayage de chaque ligne
  for ($x=0;$x<count($t_texte);$x++) {
 
    //chaque de la ligne est placée dans un tableau
    $t_mots = explode(" ", trim($t_texte[$x])); 
    //nb de mots par ligne
    $nb = count($t_mots); 
 
 
    $pos=0; //position courrante dans la ligne (init)
    $LigneFormat="";//Ligne Formatée (init)
 
    //parcours de la ligne mot par mot
    for ($i=0;$i<$nb;$i++){
 
        //mot sans les balises (taille reelle du mot)
        $st_mot=strip_tags($t_mots[$i]);
        //incrementation de la position courrante
        $pos+=strlen($st_mot);
 
        //si la position courrante est inférieure
        //a la longueur maximale parametree
        if ($pos<$maxCar){
          //position courrante incrémentee de 1 (==1 espace)
          $pos++; 
          //on ajoute le mot a la ligne formatée
          $LigneFormat.=$t_mots[$i]." "; 
        }
        //sinon on passe a la ligne (<br>)
        else {                      
          $LigneFormat.="<br>".$t_mots[$i]." ";          
          $pos = strlen($st_mot);
        }
    }
    //une fois tous les mots de la ligne traités
    //on ajoute a la variable de retour
    //  - la ligne formatée 
    //  - <BR> nouvelle ligne
    $ret.=$LigneFormat."<br>";
  }
 
  //une fois toutes les lignes traitees on retourne le
  //nouveau texte formaté
  return $ret;
}
// Commencement de création de l'image :
 
$Nom= $_POST['Nom'];
$jets = $_POST['jets'];
$taille = $_POST['taille'];
$carac = $_POST['carac'];
$DV = $_POST['DV'];
$comp = $_POST['comp'];
$initiative = $_POST['initiative'];
$dons = $_POST['dons'];
$vitesse = $_POST['vitesse'];
$milieu = $_POST['milieu'];
$CA = $_POST['CA'];
$social = $_POST['social'];
$attaques = $_POST['attaques'];
$facteur = $_POST['facteur'];
$degats = $_POST['degats'];
$tresor = $_POST['tresor'];
$espace = $_POST['espace'];
$alignement = $_POST['alignement'];
$aspe = $_POST['aspe'];
$puissance= $_POST['puissance'];
$particularites = $_POST['particularites'];
 
// création de la variable texte mis en forme
 
$texteglobaltemp = print("<b>Taille : </b>$taille <br>
		<b>Dés de vie : </b>$DV <br>
		<b>Initiative : </b>$initiative <br>
		<b>Vitesse de déplacement : </b>$vitesse <br>
	        <b>Classe d\'armure : </b>$CA <br>
		<b>Attaques : </b>$attaques <br>
		<b>Dégâts : </b>$degats <br>
		<b>Espace occupé/allonge : </b>$espace <br>
		<b>Attaques spéciales : </b>$aspe <br>
		<b>Particularités : </b>$particularites <br>
		<b>Jets de sauvegarde : </b>$jets <br>
		<b>Caractéristiques : </b>$carac <br>
		<b>Compétences : </b>$comp <br>
		<b>Dons : </b>$dons <br>
		<b>Milieu naturel/climat : </b>$milieu <br>
		<b>Organisation sociale : </b>$social <br>
		<b>Facteur de puissance : </b>$facteur <br>
		<b>Trésor : </b>$tresor <br>
		<b>Alignement : </b>$alignement <br>
		<b>Puissance possible : </b>$puissance
                ");
$texteglobal = Charparligne($texteglobaltemp,30);		
 
$image = imagecreatefrompng("cartemodele.png");
$noir = imagecolorallocate($image,0,0,0);
$rouge = imagecolorallocate($image,255,0,0);
imagestring($image,5,centrage_texte($Nom,5),100,$Nom,$rouge);
 
imagestring($image,2,80,250,$texteglobal,$noir);
header("Content-type:image\png");
imagepng($image);
 
?>
Le problème de cette page vient peut-être du "header" ou peut-être de la variable $texteglobal

J'ai également deux ou trois problèmes de mise en page pour la page 1 (tabulations), je voudrais qu'ils soient alignés (mais ca, à la rigueur je m'en fiche un petit peu...)

Voilà, donc si quelqu'un connaît les solutions à ces problèmes, merci de les faire partager please...
Halex78 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/03/2007, 00h49   #2
Membre émérite
 
Avatar de julien.63
 
Inscription : décembre 2005
Messages : 1 322
Détails du profil
Informations forums :
Inscription : décembre 2005
Messages : 1 322
Points : 981
Points : 981
Envoyer un message via MSN à julien.63
salut,
ça ressemble à un souci pour appeler l'image.
Mais je te conseille dans un premier de simplifier ton script pour ne garder que la partie qui crée l'image et celle qui l'affiche. De cette manière, tu t'assures que ceci fonctionne avant de compliquer l'affaire.
julien.63 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/03/2007, 01h01   #3
Rédacteur/Modérateur
 
Avatar de N1bus
 
Inscription : janvier 2003
Messages : 2 018
Détails du profil
Informations personnelles :
Âge : 47
Localisation : France, Charente Maritime (Poitou Charente)

Informations forums :
Inscription : janvier 2003
Messages : 2 018
Points : 1 992
Points : 1 992
Citation:
Seulement quand je veux l'executer il y a plein d'erreurs (je vois mon texte en haut de la page web et puis ensuite une page interminable de signes et lettres et chiffres
C'est le code de l'image.

Essayes de placer Header("Content-type: image/png"); au début de ton fichier, juste aprés ta balise <?php

et n'oublies pas
imagedestroy($image); à la fin
N1bus est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/03/2007, 11h22   #4
Membre chevronné
 
Avatar de haltabush
 
Développeur Web
Inscription : avril 2005
Messages : 726
Détails du profil
Informations personnelles :
Âge : 27
Localisation : France

Informations professionnelles :
Activité : Développeur Web

Informations forums :
Inscription : avril 2005
Messages : 726
Points : 790
Points : 790
Salut,
Tu t'es trompé dans le sens du slash, dans le Content-Type.
C'est image/png et pas image\png
haltabush est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/03/2007, 12h08   #5
Rédacteur/Modérateur
 
Avatar de N1bus
 
Inscription : janvier 2003
Messages : 2 018
Détails du profil
Informations personnelles :
Âge : 47
Localisation : France, Charente Maritime (Poitou Charente)

Informations forums :
Inscription : janvier 2003
Messages : 2 018
Points : 1 992
Points : 1 992
Citation:
Envoyé par haltabush
Salut,
Tu t'es trompé dans le sens du slash, dans le Content-Type.
C'est image/png et pas image\png
bien vu !
N1bus est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/03/2007, 13h16   #6
Membre chevronné
 
Avatar de haltabush
 
Développeur Web
Inscription : avril 2005
Messages : 726
Détails du profil
Informations personnelles :
Âge : 27
Localisation : France

Informations professionnelles :
Activité : Développeur Web

Informations forums :
Inscription : avril 2005
Messages : 726
Points : 790
Points : 790
Citation:
Envoyé par N1bus
bien vu !
Merci la coloration syntaxique de développez
haltabush est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/03/2007, 15h49   #7
Nouveau Membre du Club
 
Inscription : mars 2007
Messages : 71
Détails du profil
Informations forums :
Inscription : mars 2007
Messages : 71
Points : 27
Points : 27
ReBonjour,
Pour la place du header, j'ai déjà essayé de le placer au début (je me suis déjà beaucoup documenté sur les problèmes de GD grâce aux forums) mais ca n'a rien donné, j'essaierai ce soir le slash à la place de l'antislash et je vous redonnerai des nouvelles...
En tout cas, merci beaucoup de vos réponses rapides !
Halex78 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/03/2007, 21h18   #8
Nouveau Membre du Club
 
Inscription : mars 2007
Messages : 71
Détails du profil
Informations forums :
Inscription : mars 2007
Messages : 71
Points : 27
Points : 27
J'ai changé l'antislash par un slash, ca n'a rien changé.
J'ai enlevé le print() en laissant juste les guillemets devant la variable $texteglobaltemp et là, j'arrive à voir mon image avec le texte sur une longue ligne et on voit toutes les balises html (les balises n'ont pas été interprêtées et sont restées telles quelles).Si le texte n'est écrit que sur une ligne(et non formaté)
, j'en déduis que la fonction CharParLigne ne fonctionne pas. Pourtant, quand je lis le code de cette fonction, il ne me semble pas y avoir d'erreur, mais je dois sûrement me tromper !
Donc si vous avez des réponses, elles sont les bienvenues...
Halex78 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/03/2007, 21h19   #9
Nouveau Membre du Club
 
Inscription : mars 2007
Messages : 71
Détails du profil
Informations forums :
Inscription : mars 2007
Messages : 71
Points : 27
Points : 27
Oups, j'ai oublié de dire que j'avais également ajouté imagedestroy() à la fin du code...
Halex78 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/03/2007, 22h05   #10
Rédacteur/Modérateur
 
Avatar de N1bus
 
Inscription : janvier 2003
Messages : 2 018
Détails du profil
Informations personnelles :
Âge : 47
Localisation : France, Charente Maritime (Poitou Charente)

Informations forums :
Inscription : janvier 2003
Messages : 2 018
Points : 1 992
Points : 1 992
les balises ne sont pas formatées car le texte reste du texte sur l'image.

le passage à la ligne ne se fait pas avec <br> mais avec \n.
Pour le gras, je crains que tu ne soies obligé de changer de police à chaque fois avec imagettftext()

Code :
1
2
3
4
5
6
7
8
9
 
imagettftext($im, 20, 0, 10, 20, $black, $fontbold, $textgras);
//puis aprés 
imagettftext($im, $distanceL, 0, 10, 20, $black, $fontnrmal, $textnormalavecpassagealaligne);
//puis aprés
imagettftext($im, 20, $distanceH, 10, 20, $black, $fontbold, $textgras);
//puis aprés 
imagettftext($im, $distanceL, 0, 10, 20, $black, $fontnrmal, $textnormalavecpassagealaligne);
//etc
Il faut calculer à chaque fois $distanceL et $distanceH en fonction de la hauteur / largeur des mots pour positionner le texte dans l'image

Je ne sais pas s'il y a une autre solution, mais j'aurai essayé ça.
N1bus est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/03/2007, 22h31   #11
Nouveau Membre du Club
 
Inscription : mars 2007
Messages : 71
Détails du profil
Informations forums :
Inscription : mars 2007
Messages : 71
Points : 27
Points : 27
Merci, N1bus, mais le principe de mon script est qu'il 'y a pas forcément la même quantité de texte à chaque création de document... (si les textes sont à une place fixe, il se chevaucheront s'il y a trop de texte...)
Je pense que je vais créer un document php normal et essayer de l'importer en tant qu'image depuis une autre page (avec <imagesrc...> si ca fonctionne)
Tout de même, si d'autres solutions existent, merci de m'en faire part...
Halex78 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/03/2007, 22h59   #12
Rédacteur/Modérateur
 
Avatar de N1bus
 
Inscription : janvier 2003
Messages : 2 018
Détails du profil
Informations personnelles :
Âge : 47
Localisation : France, Charente Maritime (Poitou Charente)

Informations forums :
Inscription : janvier 2003
Messages : 2 018
Points : 1 992
Points : 1 992
Citation:
Envoyé par Halex78
Merci, N1bus, mais le principe de mon script est qu'il 'y a pas forcément la même quantité de texte à chaque création de document... (si les textes sont à une place fixe, il se chevaucheront s'il y a trop de texte...)
Non , tu peux calculer la largeur de ton texte à la volée avec imagettfbbox() et la reporter pour décaler les autres textes
N1bus est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/03/2007, 11h07   #13
Nouveau Membre du Club
 
Inscription : mars 2007
Messages : 71
Détails du profil
Informations forums :
Inscription : mars 2007
Messages : 71
Points : 27
Points : 27
Merci, je crois que c'est effectivement ce qu'il me faut.
Je m'y mets et je vous donne des nouvelles dès que possible .
Halex78 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/03/2007, 19h44   #14
Nouveau Membre du Club
 
Inscription : mars 2007
Messages : 71
Détails du profil
Informations forums :
Inscription : mars 2007
Messages : 71
Points : 27
Points : 27
Bon, faut croire qu'il est vraiment coriace ce php !
J'ai refait entièrement le code et il m'affiche "l'image ne peut être affichée car elle contient des erreurs"

Voici le code :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
 
<?php
header("Content-type:image/png");
 
// Fonction pour déterminer le centrage de la chaine de caractères (elle prend comme paramètre : la chaine et la police d'écriture
function centrage_texte($z,$y)
{
// Je calcule le nombre de caractères dans la chaine
$a = strlen($z);
// Je calcule la taille d'un caractère par rapport à la taille de la police
$b = imagefontwidth($y);
// Je calcule la taille de ma chaine de caractères
$c = $a*$b;
// Je calcule combien il me reste de caractères/espace sur les côtés pour centrer mon texte
$d = 525-$c;
// Je recherche l'emplacement où débutera ma chaine de caractères
$e = $d/2;
// La chaine commencera ... à cet emplacement
return $e;
} 
//******************************************
//  Limite du nombre de caractères par ligne
//
//  nom fonction : CharParLigne($texte,$maxCar)
//   - $texte : texte a formater
//   - maxCar : Nb Maxi de Caracteres par ligne
//
 
function CharParLigne($texte,$maxCar){
 
  //explosion du texte en lignes
  $t_texte=explode("\n",$texte);
  $ret="";
 
  //Balayage de chaque ligne
  for ($x=0;$x<count($t_texte);$x++) {
 
    //chaque de la ligne est placée dans un tableau
    $t_mots = explode(" ", trim($t_texte[$x])); 
    //nb de mots par ligne
    $nb = count($t_mots); 
 
 
    $pos=0; //position courrante dans la ligne (init)
    $LigneFormat="";//Ligne Formatée (init)
 
    //parcours de la ligne mot par mot
    for ($i=0;$i<$nb;$i++){
 
        //mot sans les balises (taille reelle du mot)
        $st_mot=strip_tags($t_mots[$i]);
        //incrementation de la position courrante
        $pos+=strlen($st_mot);
 
        //si la position courrante est inférieure
        //a la longueur maximale parametree
        if ($pos<$maxCar){
          //position courrante incrémentee de 1 (==1 espace)
          $pos++; 
          //on ajoute le mot a la ligne formatée
          $LigneFormat.=$t_mots[$i]." "; 
        }
        //sinon on passe a la ligne (<br>)
        else {                      
          $LigneFormat.="<br>".$t_mots[$i]." ";          
          $pos = strlen($st_mot);
        }
    }
    //une fois tous les mots de la ligne traités
    //on ajoute a la variable de retour
    //  - la ligne formatée 
    //  - <BR> nouvelle ligne
    $ret.=$LigneFormat."<br>";
  }
 
  //une fois toutes les lignes traitees on retourne le
  //nouveau texte formaté
  return $ret;
}
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////   Ici débute le script  ///////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
//
//Récupération des variables entrées par l'utilisateur :
//
$Nom= $_POST['Nom'];
$jets = $_POST['jets'];
$taille = $_POST['taille'];
$carac = $_POST['carac'];
$DV = $_POST['DV'];
$comp = $_POST['comp'];
$initiative = $_POST['initiative'];
$dons = $_POST['dons'];
$vitesse = $_POST['vitesse'];
$milieu = $_POST['milieu'];
$CA = $_POST['CA'];
$social = $_POST['social'];
$attaques = $_POST['attaques'];
$facteur = $_POST['facteur'];
$degats = $_POST['degats'];
$tresor = $_POST['tresor'];
$espace = $_POST['espace'];
$alignement = $_POST['alignement'];
$aspe = $_POST['aspe'];
$puissance= $_POST['puissance'];
$particularites = $_POST['particularites'];
//
// Variables de texte gras et normal pour imagettftext et imagettfbbox                
//
$nombre = 60 ;
 
$textetaillegras = "Taille : ";
$textetaille = CharParLigne($taille,$nombre);
 
$texteDVgras = "Dés de vie : ";
$texteDV =CharParLigne($DV,$nombre);
 
$texteinitiativegras = "initiative : ";
$texteinitiative = CharParLigne($initiative, $nombre);
 
$textevitessegras = "Vitesse de déplacement : ";
$textevitesse = CharParLigne($vitesse,$nombre);
 
$texteCAgras = "Classe d\'armure : ";
$texteCA = CharParLigne($CA,$nombre);
 
$texteattaquesgras = "Attaques : ";
$texteattaques = CharParLigne($attaques,$nombre);
 
$textedegatsgras = "Dégâts : ";
$textedegats = CharParLigne($degats,$nombre);
 
$texteespacegras = "Espace occupé/allonge : ";
$texteespace = CharParLigne($espace,$nombre);
 
$texteaspegras = "Attaques spéciales : ";
$texteaspe = CharParLigne($aspe,$nombre);
 
$texteparticularitesgras = "Particularités : ";
$texteparticularites = CharParLigne($particularites,$nombre);
 
$textejetsgras = "Jets de sauvegarde : ";
$textejets = CharParLigne($jets,$nombre);
 
$textecaracgras = "Caractéristiques : ";
$textecarac = CharParLigne($carac,$nombre);
 
$textecompgras = "Compétences : ";
$textecomp =CharParLigne($comp,$nombre);
 
$textedonsgras = "Dons : ";
$textedons = CharParLigne($dons,$nombre);
 
$textemilieugras ="Milieu naturel/climat : ";
$textemilieu = CharParLigne($milieu,$nombre);
 
$textesocialgras ="Organisation sociale : ";
$textesocial =CharParLigne($social,$nombre);
 
$textefacteurgras ="Facteur de puissance : ";
$textefacteur = CharParLigne($facteur,$nombre);
 
$textetresorgras = "Trésor : ";
$textetresor = CharParLigne($tresor,$nombre);
 
$textealignementgras = "Alignement : ";
$textealignement = CharParLigne($alignement,$nombre);
 
$textepuissancegras = "Puissance possible : ";
$textepuissance = CharParLigne($puissance,$nombre);	
//
//Création de variables communes telles que la police TrueType, la taille ..etc
//
$image = createimagefrompng("cartemodele.png");
$police = 10; 
$fontnormal = "arial.ttf"; 
$fontgras = "arialbd.ttf";
$angle = 0;
$noir = imagecolorallocate($image,0,0,0);
$rouge = imagecolorallocate($image,255,0,0);
$y = 75;
$x = 50;
//
//Création des rectangles imagettfbbox du texte normal et gras :
// les **01 correspondent aux textes en gras (ils permettent de décaler le //texte normal horizontalement) et les **02 correspondent aux textes //normaux(ils servent à décaler les textes verticalement)
$bbox0101 = imagettfbbox($police,$angle,$fontnormal,$textetaillegras);	
$bbox0102 = imagettfbbox($police,$angle,$fontnormal,$textetaille);
$bbox0201 = imagettfbbox($police,$angle,$fontnormal,$texteDVgras);
$bbox0202 = imagettfbbox($police,$angle,$fontnormal,$texteDV);
$bbox0301 = imagettfbbox($police,$angle,$fontnormal,$texteinitiativegras);
$bbox0302 = imagettfbbox($police,$angle,$fontnormal,$texteinitiative);
$bbox0401 = imagettfbbox($police,$angle,$fontnormal,$textevitessegras);
$bbox0402 = imagettfbbox($police,$angle,$fontnormal,$textevitesse);
$bbox0501 = imagettfbbox($police,$angle,$fontnormal,$texteCAgras);
$bbox0502 = imagettfbbox($police,$angle,$fontnormal,$texteCA);
$bbox0601 = imagettfbbox($police,$angle,$fontnormal,$texteattaquesgras);
$bbox0602 = imagettfbbox($police,$angle,$fontnormal,$texteattaques);
$bbox0701 = imagettfbbox($police,$angle,$fontnormal,$textedegatsgras);
$bbox0702 = imagettfbbox($police,$angle,$fontnormal,$textedegats);
$bbox0801 = imagettfbbox($police,$angle,$fontnormal,$texteespacegras);
$bbox0802 = imagettfbbox($police,$angle,$fontnormal,$texteespace);
$bbox0901 = imagettfbbox($police,$angle,$fontnormal,$texteaspegras);
$bbox0902 = imagettfbbox($police,$angle,$fontnormal,$texteaspe);
$bbox1001 = imagettfbbox($police,$angle,$fontnormal,$texteparticularitesgras);
$bbox1002 = imagettfbbox($police,$angle,$fontnormal,$texteparticularites);
$bbox1101 = imagettfbbox($police,$angle,$fontnormal,$textejetsgras);
$bbox1102 = imagettfbbox($police,$angle,$fontnormal,$textejets);
$bbox1201 = imagettfbbox($police,$angle,$fontnormal,$textecaracgras);
$bbox1202 = imagettfbbox($police,$angle,$fontnormal,$textecarac);
$bbox1301 = imagettfbbox($police,$angle,$fontnormal,$textecompgras);
$bbox1302 = imagettfbbox($police,$angle,$fontnormal,$textecomp);
$bbox1401 = imagettfbbox($police,$angle,$fontnormal,$textedonsgras);
$bbox1402 = imagettfbbox($police,$angle,$fontnormal,$textedons);
$bbox1501 = imagettfbbox($police,$angle,$fontnormal,$textemilieugras);
$bbox1502 = imagettfbbox($police,$angle,$fontnormal,$textemilieu);
$bbox1601 = imagettfbbox($police,$angle,$fontnormal,$textesocialgras);
$bbox1602 = imagettfbbox($police,$angle,$fontnormal,$textesocial);
$bbox1701 = imagettfbbox($police,$angle,$fontnormal,$textefacteurgras);
$bbox1702 = imagettfbbox($police,$angle,$fontnormal,$textefacteur);
$bbox1801 = imagettfbbox($police,$angle,$fontnormal,$textetresorgras);
$bbox1802 = imagettfbbox($police,$angle,$fontnormal,$textetresor);
$bbox1901 = imagettfbbox($police,$angle,$fontnormal,$textealignementgras);
$bbox1902 = imagettfbbox($police,$angle,$fontnormal,$textealignement);
$bbox2001 = imagettfbbox($police,$angle,$fontnormal,$textepuissancegras);
$bbox2002 = imagettfbbox($police,$angle,$fontnormal,$textepuissance);
//
//On calcule la hauteur du texte entré par l'utilisateur //le texte qui peut varier//
//
$y1 = abs($bbox0102[5]-$bbox0102[1]); $x1 = abs($bbox0101[4]-$bbox0101[0]);
$y2 = abs($bbox0202[5]-$bbox0202[1]); $x2 = abs($bbox0201[4]-$bbox0201[0]);
$y3= abs($bbox0302[5]-$bbox0302[1]);  $x3 = abs($bbox0301[4]-$bbox0301[0]);
$y4= abs($bbox0402[5]-$bbox0402[1]);  $x4 = abs($bbox0401[4]-$bbox0401[0]);
$y5= abs($bbox0502[5]-$bbox0502[1]);  $x5 = abs($bbox0501[4]-$bbox0501[0]);
$y6= abs($bbox0602[5]-$bbox0602[1]);  $x6 = abs($bbox0601[4]-$bbox0601[0]);
$y7= abs($bbox0702[5]-$bbox0702[1]);  $x7 = abs($bbox0701[4]-$bbox0701[0]);
$y8= abs($bbox0802[5]-$bbox0802[1]);  $x8 = abs($bbox0801[4]-$bbox0801[0]);
$y9= abs($bbox0902[5]-$bbox0902[1]);  $x9 = abs($bbox0901[4]-$bbox0901[0]);
$y10= abs($bbox1002[5]-$bbox1002[1]); $x10 = abs($bbox1001[4]-$bbox1001[0]);
$y11= abs($bbox1102[5]-$bbox1102[1]); $x11 = abs($bbox1101[4]-$bbox1101[0]);
$y12= abs($bbox1202[5]-$bbox1202[1]); $x12 = abs($bbox1201[4]-$bbox1201[0]);
$y13= abs($bbox1302[5]-$bbox1302[1]); $x13 = abs($bbox1301[4]-$bbox1301[0]);
$y14= abs($bbox1402[5]-$bbox1402[1]); $x14 = abs($bbox1401[4]-$bbox1401[0]);
$y15= abs($bbox1502[5]-$bbox1502[1]); $x15 = abs($bbox1501[4]-$bbox1501[0]);
$y16= abs($bbox1602[5]-$bbox1602[1]); $x16 = abs($bbox1601[4]-$bbox1601[0]);
$y17= abs($bbox1702[5]-$bbox1702[1]); $x17 = abs($bbox1701[4]-$bbox1701[0]);
$y18= abs($bbox1802[5]-$bbox1802[1]); $x18 = abs($bbox1801[4]-$bbox1801[0]);
$y19= abs($bbox1902[5]-$bbox1902[1]); $x19 = abs($bbox1901[4]-$bbox1901[0]);
$y20= abs($bbox2002[5]-$bbox2002[1]); $x20 = abs($bbox2001[4]-$bbox2001[0]);
//
//imagettftext : on affiche le texte :
//
imagettftext($image,$police,$angle,$x,$y+$y1,$noir,$fontgras,$textetaillegras);
imagettftext($image,$police,$angle,$x+$x1,$y+$y1,$noir,$fontnormal,$textetaille);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2,$noir,$fontgras,$texteDVgras);
imagettftext($image,$police,$angle,$x+$x2,$y+$y1+$y2,$noir,$fontnormal,$texteDV);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3,$noir,$fontgras,$texteinitiativegras);
imagettftext($image,$police,$angle,$x+$x3,$y+$y1+$y2+$y3,$noir,$fontnormal,$texteinitiative);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3+$y4,$noir,$fontgras,$textevitessegras);
imagettftext($image,$police,$angle,$x+$x4,$y+$y1+$y2+$y3+$y4,$noir,$fontnormal,$textevitesse);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3+$y4+$y5,$noir,$fontgras,$texteCAgras);
imagettftext($image,$police,$angle,$x+$x5,$y+$y1+$y2+$y3+$y4+$y5,$noir,$fontnormal,$texteCA);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3+$y4+$y5+$y6,$noir,$fontgras,$texteattaquesgras);
imagettftext($image,$police,$angle,$x+$x6,$y+$y1+$y2+$y3+$y4+$y5+$y6,$noir,$fontnormal,$texteattaques);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7,$noir,$fontgras,$textedegatsgras);
imagettftext($image,$police,$angle,$x+$x7,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7,$noir,$fontnormal,$textedegats);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8,$noir,$fontgras,$texteespacegras);
imagettftext($image,$police,$angle,$x+$x8,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8,$noir,$fontnormal,$texteespace);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9,$noir,$fontgras,$texteaspegras);
imagettftext($image,$police,$angle,$x+$x9,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9,$noir,$fontnormal,$texteaspe);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10,$noir,$fontgras,$texteparticularitesgras);
imagettftext($image,$police,$angle,$x+$x10,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10,$noir,$fontnormal,$texteparticularites);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11,$noir,$fontgras,$textejetsgras);
imagettftext($image,$police,$angle,$x+$x11,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11,$noir,$fontnormal,$textejets);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12,$noir,$fontgras,$textecaracgras);
imagettftext($image,$police,$angle,$x+$x12,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12,$noir,$fontnormal,$textecarac);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12+$y13,$noir,$fontgras,$textecompgras);
imagettftext($image,$police,$angle,$x+$x13,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12+$y13,$noir,$fontnormal,$textecomp);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12+$y13+$y14,$noir,$fontgras,$textedonsgras);
imagettftext($image,$police,$angle,$x+$x14,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12+$y13+$y14,$noir,$fontnormal,$textedons);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12+$y13+$y14+$y15,$noir,$fontgras,$textemilieugras);
imagettftext($image,$police,$angle,$x+$x15,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12+$y13+$y14+$y15,$noir,$fontnormal,$textemilieu);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12+$y13+$y14+$y15+$y16,$noir,$fontgras,$textesocialgras);
imagettftext($image,$police,$angle,$x+$x16,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12+$y13+$y14+$y15+$y16,$noir,$fontnormal,$textesocial);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12+$y13+$y14+$y15+$y16+$y17,$noir,$fontgras,$textefacteurgras);
imagettftext($image,$police,$angle,$x+$x17,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12+$y13+$y14+$y15+$y16+$y17,$noir,$fontnormal,$textefacteur);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12+$y13+$y14+$y15+$y16+$y17+$y18,$noir,$fontgras,$textetresorgras);
imagettftext($image,$police,$angle,$x+$x18,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12+$y13+$y14+$y15+$y16+$y17+$y18,$noir,$fontnormal,$textetresor);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12+$y13+$y14+$y15+$y16+$y17+$y18+$y19,$noir,$fontgras,$textealignementgras);
imagettftext($image,$police,$angle,$x+$x19,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12+$y13+$y14+$y15+$y16+$y17+$y18+$y19,$noir,$fontnormal,$textealignement);
 
imagettftext($image,$police,$angle,$x,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12+$y13+$y14+$y15+$y16+$y17+$y18+$y19+$y20,$noir,$fontgras,$textepuissancegras);
imagettftext($image,$police,$angle,$x+$x20,$y+$y1+$y2+$y3+$y4+$y5+$y6+$y7+$y8+$y9+$y10+$y11+$y12+$y13+$y14+$y15+$y16+$y17+$y18+$y19+$y20,$noir,$fontnormal,$textepuissance);
//
//on affiche l'image :
//
imagepng($image);
imagedestroy($image);
 
?>
Je tiens à préciser que je n'ai pas mis en page la variable $Nom
je le ferai après, une fois qque ce problème sera résolu.

Une fois de plus, si vous avez des solutions ...
Halex78 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/03/2007, 21h39   #15
Nouveau Membre du Club
 
Inscription : mars 2007
Messages : 71
Détails du profil
Informations forums :
Inscription : mars 2007
Messages : 71
Points : 27
Points : 27
j'ai trouvé l'erreur ! createimagefrompng (sacrée faute d'étourderie !).
Ca fonctionne maintenant ! MAis....mais.... il y a encore des problèmes, les textes se chevauchent !certains seulement (ouf) mais ca devient ch***t !
Bref, les travaux progressent !
La fonction revenir à la ligne ne fonctionne absolument pas, donc de ce côté là par contre, si vous avez des idées, je suis preneur !
Halex78 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 31/03/2007, 15h46   #16
Nouveau Membre du Club
 
Inscription : mars 2007
Messages : 71
Détails du profil
Informations forums :
Inscription : mars 2007
Messages : 71
Points : 27
Points : 27
Bon, un dernier message pour dire mon programme fonctionne , pour faire des retours à la ligne, j'ai utilisé les "textarea" pour faire les formulaires (c'est c** mais fallait y penser...).
Donc merci de m'avoir aidé ...
GD n'est pas très simple à utiliser, je dirais même que c'est compliqué, mais bon...
Halex78 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 15h30.


 
 
 
 
Partenaires

Hébergement Web