Forum » » Le coin des codeurs » » [Résolu] - Bug du captcha en chinois
Posté : 21 juil. 2026 à 16:53 
case 'captcha':
$mot = decrypt($att_id); // gardez en UTF-8
// Choix de la police selon la langue
if (isset($language) && $language === 'chinese') {
$fontFile = 'fonts/wqy-zenhei.ttc';
} else {
$fontFile = 'fonts/DejaVuSans.ttf';
}
// Utilisation directe de imagettftext
$fontSize = 16;
$angle = 0;
$bbox = imagettfbbox($fontSize, $angle, $fontFile, $mot);
$width = $bbox[2] - $bbox[0] + 4;
$height = $bbox[1] - $bbox[5] + 4;
$img = imagecreate($width, $height);
$blanc = imagecolorallocate($img, 255, 255, 255);
$noir = imagecolorallocate($img, 0, 0, 0);
imagecolortransparent($img, $blanc);
$x = -$bbox[0] + 2;
$y = -$bbox[5] + 2;
imagettftext($img, $fontSize, $angle, $x, $y, $noir, $fontFile, $mot);
imagepng($img);
imagedestroy($img);
break;
Cet article provient de NPDS
https://www.npds.org/viewtopic.php?topic=27112&forum=5