php - What is making the background of the image black in my code? -
i have code creates image - has background colour of black of can't seem find in code this.
also, if can show me cleaner/better/more efficient way of writing code fabulous know isn't.
the basic functionality of code create image, random numbers on used captcha type image. keeping in mind, can help?
also, might able tell, have code adds lines image attempt confuse spam bot in case tries read image. if me please write code same cleaner, thank much!
<?php session_start(); $_session['replace'] = rand(1,99999); $image = imagecreatetruecolor(80, 20); ($i=0; $i < rand(20,40); $i++) { $x = rand(0, 70); $y = rand(0, 20); imagedashedline($image, $x, $y, $x+rand(0,10), $y+rand(0,240), imagecolorallocate($image, rand(0,1),rand(0,1),rand(1,2))); imagedashedline($image, $x, $y, $x+rand(0,11), $y+rand(0,34), imagecolorallocate($image, 255,rand(50,240),rand(241,240))); } $pos_x = rand(4,15); $strarr = str_split($_session['replace']); foreach ($strarr $str){ $font_size = 5; imagestring($image,$font_size, $pos_x, $f, $str, imagecolorallocate($image, $s,$x,$s)); imagestring($image,$font_size, $pos_x, $f, $str, imagecolorallocate($image, 255,rand(50,240),rand(241,240))); $pos_x = $pos_x + rand(9,11); // letter spacing } $color = imagecolorallocate($image, 44, 44, 44); imagefill($image, 0, 0, $color); imageinterlace($image); header("content-type: image/gif"); imagegif($image); imagedestroy($image); ?>
i think it's this
$color = imagecolorallocate($image, 44, 44, 44);
at least when tried changing 44, 44, 44 -> 255, 255, 255 turns white
not sure can clean code more, when function stupidly long
imagestring($image,$font_size, $pos_x, $f, $str, imagecolorallocate($image, $s,$x,$s) );
some commenting too, if it's saying block of code does
eg: //create dotted lines distraction
or: //print image
Comments
Post a Comment