Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is where it goes wrong:</p> <pre><code>if ($darkColorR[$j]==NULL||$darkColorG[$j]==NULL||$darkColorB[$j]==NULL) </code></pre> <p>In PHP you can't compare values to NULL with $var == NULL, you have to use the is_null function:</p> <pre><code>if (is_null($darkColorR[$j])||is_null($darkColorG[$j])||is_null($darkColorB[$j])) </code></pre> <p>What this does is get the value of $darkColorR[$i] and check whether it is NULL. I think in your case you are trying to check whether the array has an entry for that specific index, which is something different entirely. You can use the isset function to check if an array has an entry with a given index:</p> <pre><code>if (!isset($darkColorR[$j])||!isset($darkColorG[$j])||!isset($darkColorB[$j])) </code></pre> <p>Putting this together gives the following code:</p> <pre><code>&lt;?php // var load $size=500; //HTTP GET vars: //N is the number of sections we have //n1 is the percentage for part1 //n2 is the percentage for part2, and so on $num=$_GET["n"]; //want to make a hard limit at 10 different sections $num=min($num,10); $percents; $angles; $angles[0]=0; $percents[0]=NULL; //load percents array. First value is NULL for ($c=1;$c&lt;=$num;$c++) { $percents[$c]=(int)$_GET["n".$c]; $angles[$c]=(int)round((($percents[$c-1]+$percents[$c])/100)*360); } $angles[$num]=360; //create image $half=round($size/2); $image = imagecreatetruecolor($size, $size); // colors $colorR=array(0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x74, 0x33, 0xFF, 0x33, 0x66); $colorG=array(0x00, 0x80, 0x00, 0xA5, 0xFF, 0xFF, 0x99, 0x00, 0x33, 0xFF); $colorB=array(0xFF, 0x00, 0x00, 0x00, 0x00, 0xD4, 0xFF, 0x66, 0x99, 0x33); // shaded colors $darkColorR=array(0x00, 0x00, 0x80, 0x80, 0x80, 0x3A, 0x1A, 0x80, 0x1A, 0x33); $darkColorG=array(0x00, 0x40, 0x00, 0x52, 0x80, 0x80, 0x4C, 0x00, 0x1A, 0x80); $darkColorB=array(0x80, 0x00, 0x00, 0x00, 0x00, 0x6A, 0x80, 0x33, 0x4C, 0x1A); $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF); $black = imagecolorallocate($image, 0x00, 0x00, 0x00); // make the 3D effect $tempDarkColor; for ($i = $half+round(.1*$half); $i &gt; $half; $i--) { for ($j=0;$j&lt;(count($angles)-1)&amp;&amp;$angles[$j]&lt;180;$j++) { if (!isset($darkColorR[$j])||!isset($darkColorG[$j])||!isset($darkColorB[$j])) { //if one of the colors is missing, set the entire color to white $darkColorR[$j]=0x00; $darkColorG[$j]=0x00; $darkColorB[$j]=0x00; } $tempDarkColor[$j]= imagecolorallocate($image, $darkColorR[$j],$darkColorG[$j],$darkColorB[$j]); imagefilledarc($image, $half, $i, $size, $half, $angles[$j], $angles[$j+1] , $tempDarkColor[$j], IMG_ARC_PIE); } } //make the image for ($k=0;$k&lt;(count($angles)-1);$k++) { if (!isset($colorR[$k])||!isset($colorG[$k])||!isset($colorB[$k])) { //if one of the colors is missing, set the entire color to white $colorR[$k]=0x00; $colorG[$k]=0x00; $colorB[$k]=0x00; } $tempColor[$k]= imagecolorallocate($image, $colorR[$k],$colorG[$k],$colorB[$k]); imagefilledarc($image, $half, $half, $size, $half, $angles[$k], $angles[$k+1] , $tempColor[$k], IMG_ARC_PIE); } // flush image header('Content-type: image/png'); imagepng($image); imagedestroy($image); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload