Core PHP

Arcs with Transparent Background with GD

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

Arcs.php

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

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

  $qRed   = imagecolorallocate($qNewImage, 255,   0,   0);
  $qWhite = imagecolorallocate($qNewImage, 255, 255, 255);
  $qBlue  = imagecolorallocate($qNewImage,   0,   0, 255);

  // First Arcs
  imagefilledarc($qNewImage, 200, 110, 400, 200,  10, 300, $qWhite,
    IMG_ARC_PIE);
  imagefilledarc($qNewImage, 200, 110, 400, 200,  10, 300, $qBlue,
    IMG_ARC_CHORD);
  imagearc($qNewImage, 200, 110, 400, 200,  300, 10, $qRed);

  // Second Arcs
  imagefilledarc($qNewImage, 200, 320, 400, 200,  10, 300, $qWhite,
    IMG_ARC_NOFILL);
  imagefilledarc($qNewImage, 200, 320, 400, 200,  10, 300, $qBlue,
    IMG_ARC_CHORD | IMG_ARC_NOFILL | IMG_ARC_EDGED);
  imagearc($qNewImage, 200, 320, 400, 200,  300, 10, $qRed);

  // Third Arcs
  imagefilledarc($qNewImage, 200, 530, 400, 200,  10, 300, $qWhite,
    IMG_ARC_EDGED);
  imagefilledarc($qNewImage, 200, 530, 400, 200,  10, 300, $qBlue,
    IMG_ARC_CHORD | IMG_ARC_EDGED);
  imagearc($qNewImage, 200, 530, 400, 200,  300, 10, $qRed);

  // Fourth Arcs
  imagefilledarc($qNewImage, 200, 740, 400, 200,  10, 300, $qWhite,
    IMG_ARC_EDGED | IMG_ARC_NOFILL);
  imagefilledarc($qNewImage, 200, 740, 400, 200,  10, 300, $qBlue,
    IMG_ARC_CHORD | IMG_ARC_NOFILL);
  imagearc($qNewImage, 200, 740, 400, 200,  300, 10, $qRed);

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

Output

 
 

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