나는 사용자가 게시 한 PHP 사이트에서 약간 수정 한 다음 기능을 사용하고 있습니다. 내가 사용/GD 문제를 상상해보십시오 (PHP)
function createImgText ($string=NULL, $fontsize=0, $marginX=0, $imgH=0, $fontfile=NULL, $imgColorHex=NULL, $txtColorHex=NULL){
if($string != ""){
//header("Content-type: image/png");
//
$spacing = 0;
$line = array("linespacing" => $spacing);
if (file_exists($fontfile)) $box = @imageftbbox($fontsize,0,$fontfile,$string,$line) or die('Box command error');
else die("ERROR - font");
$tw=$box[4]-$box[0]; //image width
$marginY = $imgH - (($imgH - $fontsize)/2);
$imgWidth = $tw + (2*$marginX);
$im = ImageCreate($imgWidth, $imgH);
$int = hexdec($imgColorHex);
$arr = array("red" => 0xFF & ($int >> 0x10),
"green" => 0xFF & ($int >> 0x8),
"blue" => 0xFF & $int);
$black = ImageColorAllocate($im, $arr["red"], $arr["green"], $arr["blue"]);
$int = hexdec($txtColorHex);
$arr = array("red" => 0xFF & ($int >> 0x10),
"green" => 0xFF & ($int >> 0x8),
"blue" => 0xFF & $int);
$white = ImageColorAllocate($im, $arr["red"], $arr["green"], $arr["blue"]);
ImageFtText($im, $fontsize, 0, $marginX, $marginY, $white, $fontfile, $string, array());
ImagePng($im);
ImageDestroy($im);
}else{
echo "ERROR - no string";
}
}
내 index.php를
error_reporting(-1);
ini_set('display_errors', true);
이미지를 출력 페이지에 다음과 같습니다.
나는 오류가 없습니다. :( 그러나, 헤더 부분의 주석 "을 이미지 오류를 포함하고 표시되지 않습니다"라고 파이어 폭스가 발생
이미지 PHP 파일 :.
<?php
error_reporting(-1);
ini_set('display_errors', true);
$code = $sys->core->generateRandomString($sys->settings['captchal']);
echo 'Debug: Using string: ' . $code . ' font: fonts/' . $sys->settings['captchaf'] . '<br>';
$sys->core->createImgText($code, 9, 10, 18, 'fonts/' . $sys->settings['captchaf'], "000000", "FFFFFF");
?>
그것은 말한다 :
Debug: Using string: nrcujP font: fonts/airstream.ttf
�PNG IHDR0�[email protected]�PLTE������������???___uV#�pIDAT�c` �E�D�x���*�s�bP �@fR�SVV``�F�[email protected]�+4h3k6 �),6F�!�P�LHPTD8� �c�p�,�8�(�8�Q+|�Q��IEND�B`�
<?php echo phpinfo(); ?>
페이지가 있는데 GD가 활성화되어 있고 모든 애드온 TTF 지원 포함. 누구나 전에 비슷한 문제가 있습니까? 나는 다른 것을 시도해 보았고 두 번째 ImageColorAllocate에서 실패한 것으로 보입니다. 내가 검색 할 때 Google에 아무런 언급이 없습니다. 호출 될 때 이미지를 렌더링 한 다음 파일 공간을 차지하지 않고 자체를 파괴한다고 가정합니다.
NXT를 사용하여 문제를 해결했습니다. 나는 공백을 두었습니다. 전에 간과 한
<?php
.
이것은 임의의 captcha 이미지를 생성하는 것입니까? – nickhar
예. 그렇습니다. 나는 그것을 처음부터 모두 쓰고있다. – LmOtaku
아직 데이터베이스에 글을 쓴 적이 없지만, 이것은 무작위 이미지를 보여주기위한 데모 코드입니다.일단 텍스트에서 무작위로 생성 된 이미지를 실제로 표시하는이 고비를 극복하면 보안에 대해 글을 쓸 것입니다. – LmOtaku