Page 1 sur 2

image de mon captcha est invisible

Posté : 28 juin 2014, 03:37
par sandaf
Bonjour!
je un probleme pour afficher l'image de mon captcha
le code en integrale est en bas
mai avant voici la ligne ou il y a le problem

Code : Tout sélectionner

imagettftext($image, $taille, $angle, $ecart*$i+15, $y, $aupifcolor, 'polices/'.$police.'.ttf', $lettre);
quand j'enleve cette ligne les ligne superposées s'affiche mai sans caractere.
merci!



<?php
/*
Neoterranos & LkY
Page captcha.php
 
Génère un captcha.
 
Quelques indications : (utiliser l'outil de recherche et rechercher les mentions données)
 
Liste des fonctions :
--------------------------
Aucune fonction
--------------------------
 
 
Liste des informations/erreurs :
--------------------------
Aucune information/erreur
--------------------------
*/
 
session_start();
header ("Content-type: image/png");
$image = imagecreate(320, 100);
 
$blanc = imagecolorallocate($image, 255, 255, 255);
$noir = imagecolorallocate($image, 0, 0, 0);
$gris = imagecolorallocate($image, 200,200,200);
$jaune = imagecolorallocate($image, 255, 255, 0);
$rouge = imagecolorallocate($image, 200, 39, 45);
$vert = imagecolorallocate($image, 45, 255, 39);
$cyan = imagecolorallocate($image, 0, 255, 255);
$magenta = imagecolorallocate($image, 200, 0, 200);
$orange = imagecolorallocate($image, 255, 160, 0);
$bleu = imagecolorallocate($image, 60, 75, 200);
$bleuclair = imagecolorallocate($image, 156, 227, 254);
$vertf = imagecolorallocate($image, 20, 140, 17);
 
/*$Anoir = imagecolorallocatealpha($image, 0, 0, 0, 80);
$Ajaune = imagecolorallocatealpha($image, 255, 255, 0, 80);
$Ablanc = imagecolorallocatealpha($image, 255, 255, 255, 80);
$Arouge = imagecolorallocatealpha($image, 200, 39, 45, 80);
$Avert = imagecolorallocatealpha($image, 45, 200, 39, 80);
$Acyan = imagecolorallocatealpha($image, 0, 255, 255, 80);
$Amagenta = imagecolorallocatealpha($image, 255, 0, 255, 80);
$Aorange = imagecolorallocatealpha($image, 255, 128, 0, 80);
$Ableu = imagecolorallocatealpha($image, 39, 45, 200, 80);
$Ableuclair = imagecolorallocatealpha($image, 156, 227, 254, 80);
 
$A2noir = imagecolorallocatealpha($image, 0, 0, 0, 25);
$A2jaune = imagecolorallocatealpha($image, 255, 255, 0, 25);
$A2blanc = imagecolorallocatealpha($image, 255, 255, 255, 25);
$A2rouge = imagecolorallocatealpha($image, 200, 39, 45, 25);
$A2vert = imagecolorallocatealpha($image, 45, 200, 39, 25);
$A2cyan = imagecolorallocatealpha($image, 0, 255, 255, 25);
$A2magenta = imagecolorallocatealpha($image, 255, 0, 255, 25);
$A2orange = imagecolorallocatealpha($image, 255, 128, 0, 25);
$A2bleu = imagecolorallocatealpha($image, 39, 45, 200, 25);
$A2bleuclair = imagecolorallocatealpha($image, 156, 227, 254, 25);*/
 
//Toutes les couleurs
$colors = Array($vert, $noir, $jaune, $blanc, $rouge, $cyan, $magenta, $orange, $bleu, $bleuclair, $gris, $vertf);
$Tcolors = count($colors);
 
/*$colors2 = Array($Avert, $Anoir, $Ajaune, $Ablanc, $Arouge, $Acyan, $Amagenta, $Aorange, $Ableu, $Ableuclair);
$Tcolors2 = count($colors2);
$colors3 = Array($A2vert, $A2noir, $A2jaune, $A2blanc, $A2rouge, $A2cyan, $A2magenta, $A2orange, $A2bleu, $A2bleuclair);
$Tcolors3 = count($colors3);*/
 
//couleurs autorisées pour les caractères
$Lcolors = Array($noir, $rouge, $magenta, $bleu, $vertf);
$TLcolors = count($Lcolors);
 
$polices = Array('baveuse3d'); //Pensez à en rajouter !!
$Tpolices = count($polices);
 
//définition des caractères autorisés.
$carac = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$Tcarac = strlen($carac);
 
//définition des lignes noires
$nb_lignes = mt_rand(3,7);
$i = 1;
while($i<=$nb_lignes)
{
        ImageLine($image, mt_rand(0,40), mt_rand(0,100), mt_rand(280, 320), mt_rand(0,100), $noir);
        $i++;
}
 
//définition des lignes colorées.
$nb_lignes = mt_rand(3,7);
$i = 1;
while($i<=$nb_lignes)
{
        ImageLine($image, mt_rand(0,40), mt_rand(0,100), mt_rand(280,320), mt_rand(0,100), $colors[mt_rand(0,$Tcolors-1)]);
        $i++;
}
 
//définition des ellipses
$nb_ellipses = mt_rand(1,6);
$i = 1;
while($i<= $nb_ellipses)
{
        ImageEllipse($image, mt_rand(0,320), mt_rand(0,100), 25+mt_rand(0,15), 25+mt_rand(0,15), $colors[mt_rand(0,$Tcolors-1)]);
        $i++;
}
 
//définition des triangles
$nb_triangles = mt_rand(1,6);
$i = 1;
while($i<=$nb_triangles)
{
        $array = Array(mt_rand(0,300), mt_rand(0,100), mt_rand(0,300), mt_rand(0,100), mt_rand(0,300), mt_rand(0,100));
        ImagePolygon($image, $array, 3, $colors[mt_rand(0,$Tcolors-1)]);
        $i++;
}
 
 
$aupifcolor = $Lcolors[mt_rand(0,$TLcolors-1)]; //la couleur des caractères
$ecart = 300/10+4; //écart entre les caractères
 
$_SESSION['captcha'] = ''; //La voilà !! Enfin !!
 
$i = 0;
while($i <= 7)
{
        $lettre = $carac[mt_rand(0, $Tcarac-1)]; //choix de lettre
        $_SESSION['captcha'] .= $lettre; //stockage
        $taille = mt_rand(35,45); //taille
        $angle = mt_rand(-35,35); //angle
        $y = mt_rand(55, 60); //ordonnée
        $police = $polices[mt_rand(0, $Tpolices-1)]; //police <img src="../../bundles/tinymce/vendor/tiny_mce/plugins/emotions/img/langue.png" title=":p" alt=":p">
         
        imagettftext($image, $taille, $angle, $ecart*$i+15, $y, $aupifcolor, 'polices/'.$police.'.ttf', $lettre);
        $i++;
}
 
imagepng($image); //On envoie et on prie <img src="../../bundles/tinymce/vendor/tiny_mce/plugins/emotions/img/langue.png" title=":p" alt=":p">
?>
sandaf

Re: image de mon captcha est invisible

Posté : 28 juin 2014, 03:42
par Elie
En mettant une police fixe ca marche chez moi ...
Soigne ca !
<?php
/*
Neoterranos & LkY
Page captcha.php
 
Génère un captcha.
 
Quelques indications : (utiliser l'outil de recherche et rechercher les mentions données)
 
Liste des fonctions :
--------------------------
Aucune fonction
--------------------------
 
 
Liste des informations/erreurs :
--------------------------
Aucune information/erreur
--------------------------
*/
 
session_start();
header ("Content-type: image/png");
$image = imagecreate(320, 100);
 
$blanc = imagecolorallocate($image, 255, 255, 255);
$noir = imagecolorallocate($image, 0, 0, 0);
$gris = imagecolorallocate($image, 200,200,200);
$jaune = imagecolorallocate($image, 255, 255, 0);
$rouge = imagecolorallocate($image, 200, 39, 45);
$vert = imagecolorallocate($image, 45, 255, 39);
$cyan = imagecolorallocate($image, 0, 255, 255);
$magenta = imagecolorallocate($image, 200, 0, 200);
$orange = imagecolorallocate($image, 255, 160, 0);
$bleu = imagecolorallocate($image, 60, 75, 200);
$bleuclair = imagecolorallocate($image, 156, 227, 254);
$vertf = imagecolorallocate($image, 20, 140, 17);
 
/*$Anoir = imagecolorallocatealpha($image, 0, 0, 0, 80);
$Ajaune = imagecolorallocatealpha($image, 255, 255, 0, 80);
$Ablanc = imagecolorallocatealpha($image, 255, 255, 255, 80);
$Arouge = imagecolorallocatealpha($image, 200, 39, 45, 80);
$Avert = imagecolorallocatealpha($image, 45, 200, 39, 80);
$Acyan = imagecolorallocatealpha($image, 0, 255, 255, 80);
$Amagenta = imagecolorallocatealpha($image, 255, 0, 255, 80);
$Aorange = imagecolorallocatealpha($image, 255, 128, 0, 80);
$Ableu = imagecolorallocatealpha($image, 39, 45, 200, 80);
$Ableuclair = imagecolorallocatealpha($image, 156, 227, 254, 80);
 
$A2noir = imagecolorallocatealpha($image, 0, 0, 0, 25);
$A2jaune = imagecolorallocatealpha($image, 255, 255, 0, 25);
$A2blanc = imagecolorallocatealpha($image, 255, 255, 255, 25);
$A2rouge = imagecolorallocatealpha($image, 200, 39, 45, 25);
$A2vert = imagecolorallocatealpha($image, 45, 200, 39, 25);
$A2cyan = imagecolorallocatealpha($image, 0, 255, 255, 25);
$A2magenta = imagecolorallocatealpha($image, 255, 0, 255, 25);
$A2orange = imagecolorallocatealpha($image, 255, 128, 0, 25);
$A2bleu = imagecolorallocatealpha($image, 39, 45, 200, 25);
$A2bleuclair = imagecolorallocatealpha($image, 156, 227, 254, 25);*/
 
//Toutes les couleurs
$colors = array($vert, $noir, $jaune, $blanc, $rouge, $cyan, $magenta, $orange, $bleu, $bleuclair, $gris, $vertf);
$Tcolors = count($colors);
 
/*$colors2 = Array($Avert, $Anoir, $Ajaune, $Ablanc, $Arouge, $Acyan, $Amagenta, $Aorange, $Ableu, $Ableuclair);
$Tcolors2 = count($colors2);
$colors3 = Array($A2vert, $A2noir, $A2jaune, $A2blanc, $A2rouge, $A2cyan, $A2magenta, $A2orange, $A2bleu, $A2bleuclair);
$Tcolors3 = count($colors3);*/
 
//couleurs autorisées pour les caractères
$Lcolors = array($noir, $rouge, $magenta, $bleu, $vertf);
$TLcolors = count($Lcolors);
 
$polices = Array('baveuse3d'); //Pensez à en rajouter !!
$Tpolices = count($polices);
 
//définition des caractères autorisés.
$carac = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$Tcarac = strlen($carac);
 
//définition des lignes noires
$nb_lignes = mt_rand(3,7);
$i = 1;
while($i<=$nb_lignes)
{
        imageline($image, mt_rand(0,40), mt_rand(0,100), mt_rand(280, 320), mt_rand(0,100), $noir);
        $i++;
}
 
//définition des lignes colorées.
$nb_lignes = mt_rand(3,7);
$i = 1;
while($i<=$nb_lignes)
{
        imageline($image, mt_rand(0,40), mt_rand(0,100), mt_rand(280,320), mt_rand(0,100), $colors[mt_rand(0,$Tcolors-1)]);
        $i++;
}
 
//définition des ellipses
$nb_ellipses = mt_rand(1,6);
$i = 1;
while($i<= $nb_ellipses) {
        imageellipse($image, mt_rand(0,320), mt_rand(0,100), 25+mt_rand(0,15), 25+mt_rand(0,15), $colors[mt_rand(0,$Tcolors-1)]);
        $i++;
}
 
//définition des triangles
$nb_triangles = mt_rand(1,6);
$i = 1;
while($i<=$nb_triangles) {
        $array = array(mt_rand(0,300), mt_rand(0,100), mt_rand(0,300), mt_rand(0,100), mt_rand(0,300), mt_rand(0,100));
        imagepolygon($image, $array, 3, $colors[mt_rand(0,$Tcolors-1)]);
        $i++;
}
 
 
$aupifcolor = $Lcolors[mt_rand(0,$TLcolors-1)]; //la couleur des caractères
$ecart = 300/10+4; //écart entre les caractères
 
$_SESSION['captcha'] = ''; //La voilà !! Enfin !!
 
$i = 0;
while($i <= 7) {
	
        $lettre = $carac[mt_rand(0, $Tcarac-1)]; //choix de lettre
        $_SESSION['captcha'] .= $lettre; //stockage
        $taille = mt_rand(35,45); //taille
        $angle = mt_rand(-35,35); //angle
        $y = mt_rand(55, 60); //ordonnée
        $police = $polices[mt_rand(0, $Tpolices-1)];
		         
        imagettftext($image, $taille, $angle, $ecart*$i+15, $y, $aupifcolor, 'rencontre/include/fonts/Standard0753.ttf', $lettre);
        $i++;
}
 
imagepng($image); //On envoie et on prie <img src="../../bundles/tinymce/vendor/tiny_mce/plugins/emotions/img/langue.png" title=":p" alt=":p">
?>

Re: image de mon captcha est invisible

Posté : 28 juin 2014, 12:01
par sandaf
Bonjour!
je ne comprend pas cette ligne et je crois que c'est cette partie qui me créer le probleme:

'rencontre/include/fonts/Standard0753.ttf' dans imagettftext

Re: image de mon captcha est invisible

Posté : 28 juin 2014, 12:12
par Elie
J'ai chargé une police a moi pour faire le test. Donc en gros c'est ta gestion des polices ttf qui merde !

Re: image de mon captcha est invisible

Posté : 28 juin 2014, 17:36
par sandaf
Comment vous faite pour créer et chargé votre police.
si je comprends bien vous avez créer ça à part puis chargé maintenant.

Re: image de mon captcha est invisible

Posté : 28 juin 2014, 18:15
par Elie
Tu crées un dossier sur ton hebergeur et tu met un fichier ttf dedans que tu appelles dans la fonction ...
Ca reste le béaba ...

Re: image de mon captcha est invisible

Posté : 29 juin 2014, 20:31
par sandaf
Bonjour!
j'ai copier tout les fichiers ttf sous windows càd C:/windows/font puis j'ai collé dans un dossier appelé polices sous_dossier de membres.
est ce que vous remarquez que l'image est très petite de telle sorte que rien ne peux s'afficher dedans?
si vous testez pour voir cela me ferrai plaisir.

Re: image de mon captcha est invisible

Posté : 29 juin 2014, 22:50
par Elie
... On va faire simple hein ...

Tu utilises WAMP ou EasyPHP pour avoir Apache sur ton serveur ?

Re: image de mon captcha est invisible

Posté : 30 juin 2014, 01:50
par sandaf
Bonjour!
j'utilise wamp server

Re: image de mon captcha est invisible

Posté : 30 juin 2014, 07:56
par Elie
Bon bah tu as /www/ton_fichier_index.php
Et tu cree /www/fonts/ et tu met tes polices dedans ...
Dans ta fonction tu met le chemin des polices :
imagettftext($image, $taille, $angle, $ecart*$i+15, $y, $aupifcolor, 'fonts/le_nom_de_la_police.ttf', $lettre);

Re: image de mon captcha est invisible

Posté : 01 juil. 2014, 03:07
par sandaf
Bonsoir!
j'ai exécute et toujours le problème persiste.
est ce que l'erreur ne vient pas de l'image appelé en entête de captcha.
le code est enregistre sous le nom de image.php
voici le code

Code : Tout sélectionner

Aucune fonction -------------------------- Liste des informations / erreurs : -------------------------- Aucune information / erreur -------------------------- */ header ("Content-type: image/png"); $count = strlen($_GET['tex']); $image = imagecreate($count*9, 18); if(function_exists(imagecolorallocatealpha)) {         $blanc = imagecolorallocatealpha($image, 255, 255, 255, 127); } else {         $blanc = imagecolorallocate($image, 255, 255, 255, 127); } $noir = imagecolorallocate($image, 0, 0, 0); imagestring($image, 5, 1, 1, htmlspecialchars($_GET['tex'], ENT_QUOTES), $noir); imagepng($image); ?>

Re: image de mon captcha est invisible

Posté : 01 juil. 2014, 12:10
par Elie
<?php

	$count = strlen($_GET['tex']);
	$image = imagecreate($count*9, 18) or die("Impossible d'initialiser la bibliothèque GD");
	$blanc = function_exists('imagecolorallocatealpha') ? imagecolorallocatealpha($image, 255, 255, 255, 127) : imagecolorallocate($image, 255, 255, 255);
	$noir = imagecolorallocate($image, 0, 0, 0);
	
	imagestring($image, 5, 1, 1, htmlspecialchars($_GET['tex'], ENT_QUOTES), $noir);
	
	header('Content-type: image/png');
	
	imagepng($image);
	imagedestroy($image);

?>
Il manquait les ' autour de imagecolorallocatealpha dans function_exists('imagecolorallocatealpha')

Re: image de mon captcha est invisible

Posté : 02 juil. 2014, 00:12
par sandaf
Bonjour!
apres le test on a l'erreur suivante:

( ! ) Notice: Undefined index: tex in C:\wamp\www\test\membres\image.php on line 23


( ! ) Warning: imagecreate(): Invalid image dimensions in C:\wamp\www\test\membres\image.php on line 24

Re: image de mon captcha est invisible

Posté : 02 juil. 2014, 00:17
par Elie
Désolé mais t'es pas fait pour le PHP.
Tu comprend pas ce que tu fais, tu comprend pas les erreurs, bref tu comprend pas ...

Fait ca : image.php?tex=Je%20Suis%20Bete

Re: image de mon captcha est invisible

Posté : 02 juil. 2014, 15:53
par Invité
Il m'a affiché que je suis bete!!!!!
je suis un bête débutant, je veux devenir intelligent.
si vous suivez un cours en classe vous comprendrez car le prof féra toujours des exemples.
mais avec des tuto c'est des casse tete, d’ailleurs on remarque que les erreurs sont faites expresses.