I'm using the following function that I slightly tweaked from the php site a user posted.
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";
}
}
I'm using the following in my index.php
error_reporting(-1);
ini_set('display_errors', true);
and the page that outputs the image.
I'm not receiving any errors. :( However, uncommenting the header portion causes Firefox to say "The image contains errors and will not be displayed".
Image php file:
<?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");
?>
It says:
Debug: Using string: nrcujP font: fonts/airstream.ttf
�PNG IHDR0�H@�PLTE������������???___uV#�pIDAT�c` �E�D�x���*�s�bP �@fR�SVV``�F�0t4UTu6uuh3rl@�+4h3k6 �),6F�!�P�LHPTD8� �c�p�,�8�( �8�Q+|�Q��IEND�B`�
I have a page with
<?php echo phpinfo(); ?>
it says GD is enabled and all addons, including TTF support. Anyone ever have a similar problem before? I've tried other things, and it seems to fail on the second ImageColorAllocate. I don't see any mention of it on google when I search. It's suppose to render an image when called then destroy itself, not take up file space.
Problem solved with the help of NXT. I had a whitespace before
<?php
that I had overlooked.