我已经设置imagealphablending
了我创建的每个图像,仍然有黑色背景。可能是什么问题呢?
$systemSettings = array(
'captcha' => array(
'colors' => array(array(30, 80, 180), array(20, 160, 40), array(220, 40, 10)),
'fonts' => array('AntykwaBold.ttf', 'Candice.ttf', 'Carbon.ttf', 'Duality.ttf', 'Heineken.ttf', 'Jura.ttf', 'StayPuft.ttf', 'TimesNewRomanBold.ttf', 'VeraSansBold.ttf'),
'size' => array('width' => '200', 'height' => '50')
)
);
function generateCaptcha() {
global $systemSettings;
$randomLetters = "abcdef";
$scale = 3;
$width = $systemSettings['captcha']['size']['width'];
$height = $systemSettings['captcha']['size']['height'];
$im = imagecreatetruecolor($width * $scale, $height * $scale);
imagealphablending($im, true);
//$GdBgColor = imagecolorallocate($im, 250, 250, 250);
//imagefilledrectangle($im, 0, 0, $width * $scale, $height * $scale, $GdBgColor);
$color = $systemSettings['captcha']['colors'][mt_rand(0, sizeof($systemSettings['captcha']['colors']) - 1)];
$GdFgColor = imagecolorallocate($im, $color[0], $color[1], $color[2]);
$fontfile = 'visual/fonts/' . $systemSettings['captcha']['fonts'][array_rand($systemSettings['captcha']['fonts'])];
$x = 20 * $scale;
$y = round(($height * 0.75) * $scale);
$length = strlen($randomLetters);
for ($i = 0; $i < $length; $i++) {
$degree = rand(-10, 10);
$fontsize = rand(20, 25) * $scale;
$letter = substr($randomLetters, $i, 1);
$coords = imagettftext($im, $fontsize, $degree, $x, $y, $GdFgColor, $fontfile, $letter);
$x += ($coords[2] - $x);
}
$k = rand(0, 100);
$xp = $scale * 12 * rand(1, 3);
for ($i = 0; $i < ($width * $scale); $i++)
imagecopy($im, $im, $i - 1, sin($k + $i / $xp) * ($scale * 5), $i, 0, 1, $height * $scale);
$k = rand(0, 100);
$yp = $scale * 12 * rand(1, 3);
for ($i = 0; $i < ($height * $scale); $i++)
imagecopy($im, $im, sin($k + $i / $yp) * ($scale * 14), $i - 1, 0, $i, $width * $scale, 1);
imagefilter($im, IMG_FILTER_GAUSSIAN_BLUR);
$imResampled = imagecreatetruecolor($width, $height);
imagecopyresampled($imResampled, $im, 0, 0, 0, 0, $width, $height, $width * $scale, $height * $scale);
imagealphablending($imResampled, true);
header("Content-type: image/png");
imagepng($imResampled);
imagedestroy($im);
imagedestroy($imResampled);
}