PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了PHP GD图形的平滑断续图像线大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我无法获得该图的平滑线.我尝试过抗锯齿,增加了图像,并且在PHP.net上发现了一些平滑功能,但结果不一致,有时会导致断行.

我更新了下面的代码,并显示/评论了用于修复问题的更改

编码:

<?PHP
header("Content-type: image/png");

$Values=array(rand(40,80),rand(40,100),rand(10,50),rand(80,160),rand(30,100),rand(40,120),rand(280,360),rand(20,80),rand(10,80),rand(40,120),rand(180,260),rand(40,160),rand(550,700),rand(480,600),rand(240,340),rand(480,600),rand(240,340));
$imgWidth=500;
$imgHeight=200;
$grid=25;
$graphspacing=0.05;

while (list($key, $val) = each($Values)) {
    if($val>$maX){
        $max=$val;
    }
}

for ($i=0; $i<count($Values); $i++){
    $graphValues[$i] = $Values[$i] * (($imgHeight*(1-$graphspacing))/$maX);
}

// use imagecreatetruecolor instead of imagecreate
$image=imagecreatetruecolor($imgWidth, $imgHeight);

// added antialiasing
imageantialias($image, truE);

// had to force a white bg
$bgColor = imagecolorallocate($image, 255, 255, 255);
imagefill($image , 0,0 , $bgColor);

$colorWhite=imagecolorallocate($image, 255, 255, 255);
$colorGrey=imagecolorallocate($image, 192, 192, 192);
$colorBlue=imagecolorallocate($image, 0, 0, 255);

imageline($image, 0, 0, 0, $imgHeight, $colorGrey);
imageline($image, 0, 0, $imgWidth, 0, $colorGrey);
imageline($image, $imgWidth-1, 0, $imgWidth-1, $imgHeight-1, $colorGrey);
imageline($image, 0, $imgHeight-1, $imgWidth-1, $imgHeight-1, $colorGrey);

// Create grid
for ($i=1; $i<($imgWidth/$grid); $i++) {
    imageline($image, $i*$grid, 0, $i*$grid, $imgHeight, $colorGrey);
}
for ($i=1; $i<($imgHeight/$grid); $i++) {
    imageline($image, 0, $i*$grid, $imgWidth, $i*$grid, $colorGrey);
}

if($imgWidth/$grid>count($graphValues)){ 
    $space=$grid; 
} else { 
    $space = $imgWidth/(count($graphValues)-1);
}

for ($i=0; $i<count($graphValues)-1; $i++) {
    imageline($image, $i*$space, ($imgHeight-$graphValues[$i]), ($i+1)*$space, ($imgHeight-$graphValues[$i+1]), $colorBluE);
}

//添加了平滑过滤器
imagefilter($image,IMG_FILTER_SMOOTH,15);

imagepng($imagE);//,NULL,9);
imagedestroy($imagE);

?>

结果是(最好的结果):

之前

干杯

解决方法:

您正在使用imagecreate,我建议使用imagecreatetruecolor,然后向该图像添加imageantialias ….(在您的代码中看不到任何imageantialias)

总有区别

我建议您看一下http://php.net/manual/en/function.imageantialias.php的例子

我希望这有帮助

谢谢

大佬总结

以上是大佬教程为你收集整理的PHP GD图形的平滑断续图像线全部内容,希望文章能够帮你解决PHP GD图形的平滑断续图像线所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: