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 25/07/2007, 16h58   #1
Débutant
 
Inscription : mai 2005
Messages : 1 961
Détails du profil
Informations personnelles :
Localisation : Suisse

Informations forums :
Inscription : mai 2005
Messages : 1 961
Points : 615
Points : 615
Par défaut gd génère un message d'erreur

Bonjour,
Ca fait quelque jour que je casse la tete avec ce code qui genere des lettres sous forme d'image. Voici le code de la page anti_span.php


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
<?php 
session_start();
$strlen= (int)4;
$width = $strlen * 30 + 21;
$height = 60;
// création
$img = imagecreatetruecolor($width,$height)or die ("Impossible de crée un flux d'image GD");
// antialising, c'est plus bô! :-)
imageantialias( $img, 1 );
// chaine
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$chaine = '';
for( $i = 0; $i < $strlen; $i++ ){
	$chaine .= $string[ mt_rand( 0, 35 ) ];
	$_SESSION['spood'] = $chaine;
	// couleur de départ
	$c1 = array( mt_rand( 200, 255), mt_rand( 200, 255), mt_rand( 200, 255) );
	// couleur finale
	$c2 = array( mt_rand( 150, 200), mt_rand( 150, 200), mt_rand( 150, 200) );
	$colors = array( 
		imagecolorallocate( $img, 70, 130, 255 ) , 
		imagecolorallocate( $img, 255, 237, 175 ), 
		imagecolorallocate( $img, 166, 250, 186 ), 
		imagecolorallocate( $img, 253, 188, 251 ), 
		imagecolorallocate( $img, 255, 255, 255 ) 
		);
}						
	// création de l'image
for( $i = 0; $i < $width; $i++ ){
	$r = $c1[0] + $i * ( $c2[0] - $c1[0] ) / $width;
	$v = $c1[1] + $i * ( $c2[1] - $c1[1] ) / $width;
	$b = $c1[2] + $i * ( $c2[2] - $c1[2] ) / $width;
	$color = imagecolorallocate( $img, $r, $v, $b );
 
	imageline( $img, $i, 0, $i, $height, $color );
}
// caractères
for( $i = 0; $i < $strlen; $i++ ){
	$col = imagecolorallocate( $img, mt_rand( 0, 120 ),mt_rand( 0, 120 ), mt_rand( 0, 120 ));
	imagettftext( $img, mt_rand( 20, 25 ), 
	mt_rand( -30, 30 ), 
	10 + $i * 30, 35, 
	$col, 
	'comic.ttf', 
	$chaine[ $i ] );
}
// quelques lignes qui embêtent
for( $i = 0; $i < 8; $i++ ){
	imageline( $img, mt_rand(0, $width), 
	mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $colors[mt_rand( 0, 4 )] );
}
 
$noir = imagecolorallocate( $img, 0, 0, 0 );
 
// bordure
imageline( $img, 0, 0, $width, 0, $noir );
imageline( $img, 0, 0, 0, $height, $noir );
imageline( $img, $width - 1, 0, $width - 1, $height, $noir );
// header: image
header("Content-type: image/png");
imagepng( $img ); 
imagedestroy( $img );	
?>
Sur le serveur web de mon entreprise, il affiche ce message d'erreur:
Citation:
The image “http://www.dom.ch/include/en/contact/anti_spam.php” cannot be displayed, because it contains errors.
Code :
1
2
 
<img src="http://www.dom.ch/include/en/contact/anti_spam.php" alt="The image “http://www.dom.ch/include/en/contact/anti_spam.php” cannot be displayed, because it contains errors."/>
Par contre, sur mon serveur local easyPHP, ca fonctionne tout bien

Avez vous une idee?

Merci pour votre aide
__________________
Il ne suffit pas de tout savoir. Vouloir et persévérer, c'est déjà presque tout!
pierrot10 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/07/2007, 17h02   #2
Membre du Club
 
Inscription : novembre 2004
Messages : 151
Détails du profil
Informations personnelles :
Âge : 27

Informations forums :
Inscription : novembre 2004
Messages : 151
Points : 69
Points : 69
t'as essayé de générer ton image ds un fichier
puis d'afficher le fichier .
c'est à dire d'écrire :
<img src ="xxx.png" />

au lieu de xxx.php ??
Juste pour voir ce que ca donne ?
AsQuel est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/07/2007, 17h03   #3
Modérateur
 
Avatar de mathieu
 
Inscription : juin 2003
Messages : 4 893
Détails du profil
Informations forums :
Inscription : juin 2003
Messages : 4 893
Points : 4 466
Points : 4 466
vas directement à l'URL de l'image avec le navigateur pour regarder si tu as des messages d'erreur
__________________
Modérateur PHP
mathieu est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/07/2007, 18h13   #4
Débutant
 
Inscription : mai 2005
Messages : 1 961
Détails du profil
Informations personnelles :
Localisation : Suisse

Informations forums :
Inscription : mai 2005
Messages : 1 961
Points : 615
Points : 615
mais je ne vois pas comment puisque l'image est générée par le code de la page http://www.dom.ch/include/en/contact/anti_spam.php

L'url de l'image est
Code :
<img src="http://www.dom.ch/include/en/contact/anti_spam.php" alt="L'image “http://www.dom.ch/include/en/contact/anti_spam.php” ne peut être affichée car elle contient des erreurs."/>
A min que j'ai mal compris ce que tu veux dire
__________________
Il ne suffit pas de tout savoir. Vouloir et persévérer, c'est déjà presque tout!
pierrot10 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2007, 08h36   #5
Débutant
 
Inscription : mai 2005
Messages : 1 961
Détails du profil
Informations personnelles :
Localisation : Suisse

Informations forums :
Inscription : mai 2005
Messages : 1 961
Points : 615
Points : 615
Salut AsQuel,
Oui je viens d'essayer et ca marche l'image png est bien affichée

Any help?
Merci
__________________
Il ne suffit pas de tout savoir. Vouloir et persévérer, c'est déjà presque tout!
pierrot10 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2007, 09h21   #6
Débutant
 
Inscription : mai 2005
Messages : 1 961
Détails du profil
Informations personnelles :
Localisation : Suisse

Informations forums :
Inscription : mai 2005
Messages : 1 961
Points : 615
Points : 615
Je crois avoir une bonne piste,
je suis tombé sur ceci
http://ch2.php.net/gd
un peu plus bas il dise de commenté le header.
Citation:
If you are getting the generic error "The image cannot be displayed, because it contains errors.", comment out header("Content-type: image/png");. This will enable PHP to display the real PHP errors.
Je l'ai fait et j'ai ce message qui m'est venu
Citation:
Warning: imagettftext(): Could not find/open font in /data/lasep/include/en/contact/anti_spam.php on line 46
Intéressant!

A cette ligne j'ai ceci
Code :
1
2
3
4
5
6
7
8
9
10
11
 
// caractères
for( $i = 0; $i < $strlen; $i++ ){
	$col = imagecolorallocate( $img, mt_rand( 0, 120 ),mt_rand( 0, 120 ), mt_rand( 0, 120 ));
	imagettftext( $img, mt_rand( 20, 25 ), 
	mt_rand( -30, 30 ), 
	10 + $i * 30, 35, 
	$col, 
	'comic.ttf', 
	$chaine[ $i ] );
}
Je crois que ceci est parce que mon easyPHP tourne sur un Window et le serveur web sur Apache. Donc les police ne sont pas placé au meme endroit, ou on pas le meme nom.

Non?
__________________
Il ne suffit pas de tout savoir. Vouloir et persévérer, c'est déjà presque tout!
pierrot10 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/07/2007, 00h29   #7
Membre habitué
 
Avatar de nico le terrible
 
Inscription : novembre 2004
Messages : 163
Détails du profil
Informations forums :
Inscription : novembre 2004
Messages : 163
Points : 107
Points : 107
Met ta police dans le dossier ou ce trouve ton script et ça devrait marcher
nico le terrible 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 10h08.


 
 
 
 
Partenaires

Hébergement Web