| | |||||||
| |||||||
| |||||||
|
|
|
|
|
|
|
Draws a simple GD pie chart showing used space over total space. Requires GD of course. You can also find more scripts on my site here By : andrew <?php define("DISK","/home/"); //Enter the Drive/Mount point/Directory that you want to generate a space usage graph for. $total = round(disk_total_space(DISK)/1024/1024,2); //Get the total diskspace $free = round(disk_free_space(DISK)/1024/1024,2); $used = $total - $free; //Find used space $used = round(($used/$total)*100); //Calculate used space when rounded $free = round(($free/$total)*100); //Calculate free space //Generate pie chart define("WIDTH", 500); //Width may break if changed define("HEIGHT", 220); //Again height may break it when changed $data[0] = $used; $data[1] = $free; $img = imagecreate(WIDTH-100, HEIGHT); //Start the images $background = $white = imagecolorallocate($img, 112,128,144); //Set background $black = imagecolorallocate($img, 0, 0, 0); //Set colours, black in this case $center_x = (int)WIDTH/2; //Calculate image centre for x $center_y = (int)HEIGHT/2; //Calculate image centre for y imagerectangle($img, 0, 0, WIDTH-101, HEIGHT-1, $black); //Draw the backrgound border $color[0] = imagecolorallocate($img, 159,182,205); $color[1] = imagecolorallocate($img, 198,226,255); $last_angle = 0; //Draw the pie chart on the percentage of disk space for($i=0; $i<count($data); $i++) { $arclen = (360 * $data[$i]) / 100; imagefilledarc($img, $center_x - 120, $center_y, 200, 200, $last_angle, ($last_angle + $arclen), $color[$i],IMG_ARC_PIE); $last_angle += $arclen; } //Turn the used space into gigabytes $used = round(($used*$total)/100/1024,2); imagestring($img, 5, 250, $center + 30, "Used Space: ".$data[0]."%", $color[0]); //Draw info onto the main shape imagestring($img, 5, 250, $center + 60, "Free Space: ".$data[1]."%", $color[1]); //Same as above but for free space imagerectangle($img, 240, $center+10, 390, $center+100, $black); imagestring($img, 5, $center_x, $center + 200, $used."Gb / ".($total/1024)."Gb", $black); // Used space / Total Space header("Content-Type: image/png"); //Content type png imagepng($img); //Draw image to browser imagedestroy($img); //Destroy the image resource ?>
More File Manipulation Code Articles |
| |
| |