GD PHP

Drawing Circles with Alpha Blending

This PHP program demonstrates how to draw circles on an image with blending based on the alpha channel with the Graphics Draw, GD, library.

DrawingCirclesWithAlpha.php

<?php
  // Create a 400 by 400 pixel image
  $qImage = imagecreatetruecolor(400, 400);
  // Create a color for the image: (Image, Red, Green, Blue)
  $qWhite = imagecolorallocate($qImage, 255, 255, 255);

  // Use imagesx() and imagesy() to draw a rectangle over the entire image
  // Format: (Image, UpLeftX, UpLeftY, LowRightX, LowRightY, Color)
  imagefilledrectangle($qImage, 0, 0, imagesx($qImage), imagesy($qImage), $qWhite);

  for($i = 0; $i < 256; $i = $i + 20) {
    // Alpha value run from 0 to 127 with 127 being transparent
    $qAlphaColor = imagecolorallocatealpha($qImage, $i, 0, 0, 80 + ceil(rand(0,30)));
    // Format: (Image, CenterX, CenterY, Width, Height, Color)
    imagefilledellipse($qImage, $i, $i, $i, $i, $qAlphaColor);
  }

  header("content-type: image/png");
  imagepng($qImage);
  imagedestroy($qImage);
?>
 

Output

 
 

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