php Color Handling

The GD library supports both 8-bit palette (256 color) images and true color images with alpha channel transparency.

To create an 8-bit palette image, use the imagecreate() function. The image’s background is subsequently filled with the first color you allocate using imagecolorallocate():

A simple orange ellipse on a white background

<?php
$image = imagecreatetruecolor(150, 150);
$white = imagecolorallocate($image, 255, 255, 255);
imagealphablending($image, false);
imagefilledrectangle($image, 0, 0, 150, 150, $white);
$red = imagecolorallocatealpha($image, 255, 50, 0, 50);
imagefilledellipse($image, 75, 75, 80, 63, $red);
header("Content-Type: image/png");
imagepng($image);
?>
An orange ellipse on a white background

Leave a Comment