Core PHP

3D Pie Chart with Transparent Background with GD

This GD example program demonstrates the code for an example program that demonstrates how to draw a 3D pie chart with a transparent background with GD and create a png image.

PieChart3D.php

<?php
  // Create an image object
  $qNewImage = imagecreatetruecolor(400, 400);

  // Make the background transparent
  imagealphablending($qNewImage, false);
  $qTransparent = imagecolorallocatealpha($qNewImage, 0, 0, 0, 127);
  imagefill($qNewImage, 0, 0, $qTransparent);
  imagesavealpha($qNewImage, true);

  // Allocate colors and shadows
  $qYellow    	= imagecolorallocate($qNewImage, 0xFF, 0xFF, 0x00);
  $qDarkYellow  = imagecolorallocate($qNewImage, 0x90, 0x90, 0x00);
  $qMagenta    	= imagecolorallocate($qNewImage, 0xFF, 0x00, 0xFF);
  $qDarkMagenta = imagecolorallocate($qNewImage, 0x90, 0x00, 0x90);
  $qRed         = imagecolorallocate($qNewImage, 0xFF, 0x00, 0x00);
  $qDarkRed   	= imagecolorallocate($qNewImage, 0x90, 0x00, 0x00);

  // Draw the dark shadows, bottom to top
  for ($i = 240; $i > 200; $i--) {
    imagefilledarc($qNewImage, 200, $i, 400, 200,   0,  65, $qDarkMagenta, IMG_ARC_PIE);
    imagefilledarc($qNewImage, 200, $i, 400, 200,  65, 135, $qDarkRed, IMG_ARC_PIE);
    imagefilledarc($qNewImage, 200, $i, 400, 200, 135, 360, $qDarkYellow,  IMG_ARC_PIE);
  }
  // Draw the top colors
  imagefilledarc($qNewImage, 200, 200, 400, 200,   0,  65, $qMagenta, IMG_ARC_PIE);
  imagefilledarc($qNewImage, 200, 200, 400, 200,  65, 135, $qRed, IMG_ARC_PIE);
  imagefilledarc($qNewImage, 200, 200, 400, 200, 135, 360, $qYellow,  IMG_ARC_PIE);

  // Create the image file
  header('Content-type: image/png');
  imagepng($qNewImage);
  imagedestroy($qNewImage);
?>
 

Output

 
 

© 2007–2024 XoaX.net LLC. All rights reserved.