website logo
Auteur
avatar
Visiteur

Forum » » Le coin des codeurs » » [Résolu] - Bug du captcha en chinois


Posté : 21 juil. 2026 à 23:27 icone du post

donc dans ton getfile.php



case 'captcha':
$mot = decrypt($att_id); // on garde en UTF-8, pas besoin de conversion ISO avec imagettftext

// Détection des caractères chinois (CJK) dans le texte, plutôt que de dépendre
// d'une variable de langue du site qui peut ne pas correspondre au texte du captcha
$fontsDir = 'fonts/'; // adapter au chemin réel du dossier fonts sur ton serveur

$fontFile = preg_match('/[\x{4e00}-\x{9fff}]/u', $mot)
? $fontsDir . 'wqy-zenhei.ttc'
: $fontsDir . 'DejaVuSans.ttf';

$fontSize = 16;
$angle = 0;
$bbox = imagettfbbox($fontSize, $angle, $fontFile, $mot);
$width = abs($bbox[2] - $bbox[0]) + 8;
$height = abs($bbox[1] - $bbox[7]) + 8;

$img = imagecreatetruecolor($width, $height);
$blanc = imagecolorallocate($img, 255, 255, 255);
$noir = imagecolorallocate($img, 0, 0, 0);
imagefill($img, 0, 0, $blanc);
imagecolortransparent($img, $blanc);

$x = -$bbox[0] + 4;
$y = -$bbox[7] + 4;
imagettftext($img, $fontSize, $angle, $x, $y, $noir, $fontFile, $mot);

imagepng($img);

// depuis PHP 8.0, imagedestroy() n'a plus aucun effet —
// depuis PHP 8.0, l'extension GD utilise des objets au lieu de ressources,
// et les objets ne peuvent pas être fermés explicitement.
// Et cette fonction a été officiellement dépréciée à partir de PHP 8.5,
// ce qui déclenche maintenant un warning si tu es sur PHP 8.5+
imagedestroy($img);
if (PHP_VERSION_ID < 80000) {
imagedestroy($img);
}
break;
 Message édité par : nicolas2 / 21/07/2026 23:32

Cet article provient de NPDS
https://www.npds.org/viewtopic.php?topic=27112&forum=5