imagecolorallocate - No Effect
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

imagecolorallocate - No Effect

From: afrinspray <afrinspray@gmail.com>
Date: Thu Apr 06 2006 - 19:53:36 CEST

I'm having trouble with the imagecolorallocate 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('session.php');
include_once('functions.php');

$strCode = randomcode(6);
$_SESSION['strCode'] = $strCode;

$bgdir = 'images/verification/';
$bgs = array('bg1.png', 'bg2.png', 'bg3.png');
$im = ImageCreateFromPNG($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 = ImageColorAllocate($im, rand(0, 50), rand(0, 50), rand(0,
50));
$color = imagecolorallocate($im, 0, 0, 0);

$textsize = imagettfbbox($size, $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($im, $size, $angle, $x, $y, $color, $font, $strCode);

header("Content-Type: image/png");
imagepng($im);

imagedestroy($im);

exit;

?>

Thanks,
Mike
Received on Mon May 1 02:49:48 2006