I'm having trouble with the imagecoloralloc ate function. I'm creating
a security image, and the color of the text changes depending on the
background for some reason (ie, for one background the text is always
black, one is always pink, and the other is always yellow).
Any ideas? I'm running Freebsd.
Here's my code:
<?php
include_once('s ession.php');
include_once('f unctions.php');
$strCode = randomcode(6);
$_SESSION['strCode'] = $strCode;
$bgdir = 'images/verification/';
$bgs = array('bg1.png' , 'bg2.png', 'bg3.png');
$im = ImageCreateFrom PNG($bgdir.$bgs[rand(0, count($bgs)-1)]);
$font = '/usr/X11R6/lib/X11/fonts/urwfonts-ttf/n021003l.ttf';
$size = rand(12, 16);
$angle = rand(-5, 5);
//$color = ImageColorAlloc ate($im, rand(0, 50), rand(0, 50), rand(0,
50));
$color = imagecoloralloc ate($im, 0, 0, 0);
$textsize = imagettfbbox($s ize, $angle, $font, $strCode);
$twidth = abs($textsize[2]-$textsize[0]);
$theight = abs($textsize[5]-$textsize[3]);
$x = (imagesx($im)/2)-($twidth/2)+(rand(-20, 20));
$y = (imagesy($im))-($theight/2);
imagettftext($i m, $size, $angle, $x, $y, $color, $font, $strCode);
header("Content-Type: image/png");
imagepng($im);
imagedestroy($i m);
exit;
?>
Thanks,
Mike
a security image, and the color of the text changes depending on the
background for some reason (ie, for one background the text is always
black, one is always pink, and the other is always yellow).
Any ideas? I'm running Freebsd.
Here's my code:
<?php
include_once('s ession.php');
include_once('f unctions.php');
$strCode = randomcode(6);
$_SESSION['strCode'] = $strCode;
$bgdir = 'images/verification/';
$bgs = array('bg1.png' , 'bg2.png', 'bg3.png');
$im = ImageCreateFrom PNG($bgdir.$bgs[rand(0, count($bgs)-1)]);
$font = '/usr/X11R6/lib/X11/fonts/urwfonts-ttf/n021003l.ttf';
$size = rand(12, 16);
$angle = rand(-5, 5);
//$color = ImageColorAlloc ate($im, rand(0, 50), rand(0, 50), rand(0,
50));
$color = imagecoloralloc ate($im, 0, 0, 0);
$textsize = imagettfbbox($s ize, $angle, $font, $strCode);
$twidth = abs($textsize[2]-$textsize[0]);
$theight = abs($textsize[5]-$textsize[3]);
$x = (imagesx($im)/2)-($twidth/2)+(rand(-20, 20));
$y = (imagesy($im))-($theight/2);
imagettftext($i m, $size, $angle, $x, $y, $color, $font, $strCode);
header("Content-Type: image/png");
imagepng($im);
imagedestroy($i m);
exit;
?>
Thanks,
Mike
Comment