2012-04-02 12 views
3

このグラフでは滑らかな線が得られません。私はアンチエイリアスを試み、イメージを増やし、php.netでいくつかのスムージング機能を見つけましたが、結果は一貫していません。PHP GDグラフのスムーズなホメオライン

私は以下のコードを更新し、

にコードを問題を解決するために使用さCHANGESコメント/示した:

<?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($イメージ、IMG_FILTER_SMOOTH、15を追加しました);

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

?> 

結果は(私はまだ得ている最高)です:

enter image description here

Chの後

enter image description here

eers.Bo

私は、そのイメージに imageantialiasを追加 imagecreatetruecolorを使用してアドバイスう imagecreateを使用している
+0

ちょうどよい例を持つために、init '$ max = 0'はmssingです。 – MaxD

答えて

3

....常に常にあり

違いを(あなたのコード内の任意のimageantialiasを参照することはできません)

私は、これは

おかげ

を役に立てば幸い http://php.net/manual/en/function.imageantialias.php

での例を見てあなたをアドバイスう

:)

+0

私はそれを見落とした微妙な区別だと思います。 – roberthuttinger

+0

クール..私は助けることができたと思う。 – Baba

+0

私は作業上の修正を示すために上記のコードを変更しました。事実の後、私はそれをより良くしたSMOOTHフィルターを追加しました。 – roberthuttinger