| |
01 02 03 04 05 06 07 08 09 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
<?php
/*------------------------------*/
/*
Titre : Captcha - Générateur d'images
Auteur : developpeurweb
Date édition : 15 Avril 2011
Date mise a jour : 19 Sept 2019
Rapport de la maj:
- fonctionnement du code vérifié
*/
/*------------------------------*/
// Paramètres
$width = 1280;
$height = 360;
$scale = 1/4;
$bg_color = array(0,0,0);
$fg_color = array(200,0,0);
// Initialisation de l'image
$font = dirname(__FILE__)."/font.ttf";
$bg_color[2]);
$fg_color[2]);
// Génération du texte,
function random_word($n){
$charsets = array("aeiouy", "bcdfghjklmnpqrstvwxz");
$word = "";
for ($i=$i0 ; $i<$i0+$n ; $i++){
$charset = $charsets[$i%2];
$word.= $letter;
}
}
function random_sentence(){
$n2 = 9 - $n1;
return random_word($n1)." ".random_word($n2);
}
$sentence = random_sentence();
imagettftext($img, 120, 0, 128, 320, $img_fg_color, $font, $sentence);
// Ajout d'une ligne horizontale
imagefilledrectangle($img, 0, $y, $width, $y+6, $img_fg_color);
// Déformation de l'image
function random_phase(){
return 2 * M_PI * rand() / getrandmax();
}
$phase1 = random_phase();
$phase2 = random_phase();
function y($x){
global $phase1, $phase2, $y;
return 96 * (1 + sin($x/M_PI/32 + $phase1)) * (1 + sin($y/M_PI/17 -
$phase2));
}
function x($y){
global $phase1, $phase2;
return 32 * (1 + sin($y/M_PI/32 + $phase2)) * (1 + sin($y/M_PI/97 -
$phase1));
}
for($x=0 ; $x<$width ; $x+=1){
$y = y($x);
imagecopy($img, $img, $x, 0, $x, $y, 1, $height);
imagefilledrectangle($img, $x, $height-$y, $x, $height, $img_bg_color);
}
for($y=0 ; $y<$width ; $y+=1){
$x = x($y);
imagecopy($img, $img, 0, $y, $x, $y, $width, 1);
imagefilledrectangle($img, $width-$x, $y, $width, $x, $img_bg_color);
}
// Redimensionnement de l'image
imagecopyresampled($img_resized,$img, 0,0,0,0, $width*$scale,$height*$scale,
$width,$height);
// Le texte sera stocké dans une variable de session pendant 1 minute
$_SESSION["captcha"] = $sentence;
// Envoi de l'image redimensionnée
Header("Content-Type: image/png");
?>
<?php
/*------------------------------*/
/*
Titre : Captcha - Générateur d'images
Auteur : developpeurweb
Date édition : 15 Avril 2011
Date mise a jour : 19 Sept 2019
Rapport de la maj:
- fonctionnement du code vérifié
*/
/*------------------------------*/
// Paramètres
$width = 1280;
$height = 360;
$scale = 1/4;
$bg_color = array(0,0,0);
$fg_color = array(200,0,0);
// Initialisation de l'image
$font = dirname(__FILE__)."/font.ttf";
$bg_color[2]);
$fg_color[2]);
// Génération du texte,
function random_word($n){
$charsets = array("aeiouy", "bcdfghjklmnpqrstvwxz");
$word = "";
for ($i=$i0 ; $i<$i0+$n ; $i++){
$charset = $charsets[$i%2];
$word.= $letter;
}
}
function random_sentence(){
$n2 = 9 - $n1;
return random_word($n1)." ".random_word($n2);
}
$sentence = random_sentence();
imagettftext($img, 120, 0, 128, 320, $img_fg_color, $font, $sentence);
// Ajout d'une ligne horizontale
imagefilledrectangle($img, 0, $y, $width, $y+6, $img_fg_color);
// Déformation de l'image
function random_phase(){
return 2 * M_PI * rand() / getrandmax();
}
$phase1 = random_phase();
$phase2 = random_phase();
function y($x){
global $phase1, $phase2, $y;
return 96 * (1 + sin($x/M_PI/32 + $phase1)) * (1 + sin($y/M_PI/17 -
$phase2));
}
function x($y){
global $phase1, $phase2;
return 32 * (1 + sin($y/M_PI/32 + $phase2)) * (1 + sin($y/M_PI/97 -
$phase1));
}
for($x=0 ; $x<$width ; $x+=1){
$y = y($x);
imagecopy($img, $img, $x, 0, $x, $y, 1, $height);
imagefilledrectangle($img, $x, $height-$y, $x, $height, $img_bg_color);
}
for($y=0 ; $y<$width ; $y+=1){
$x = x($y);
imagecopy($img, $img, 0, $y, $x, $y, $width, 1);
imagefilledrectangle($img, $width-$x, $y, $width, $x, $img_bg_color);
}
// Redimensionnement de l'image
imagecopyresampled($img_resized,$img, 0,0,0,0, $width*$scale,$height*$scale,
$width,$height);
// Le texte sera stocké dans une variable de session pendant 1 minute
$_SESSION["captcha"] = $sentence;
// Envoi de l'image redimensionnée
Header("Content-Type: image/png");
?>
|
Developpeurweb
30 Mai 2011 à 08:46Le bon fonctionnement du script ne dépend pas de l'OS, mais il faut s'assurer que la librairie GD soit correctement installée et configurée.
Dan4
30 Mai 2011 à 06:48Fonctionne pas sous Windows avec wampserver. Sous linux oui.