How does the ALPHA parameter work in PHP when adjusting the opacity of an image?

When adjusting the opacity of an image in PHP, the ALPHA parameter is used in combination with the imagecolorallocatealpha() function to set the transparency level. The ALPHA parameter ranges from 0 (completely transparent) to 127 (completely opaque). By setting the ALPHA parameter to a specific value, you can control the opacity of the image.

// Create a new image with transparency
$image = imagecreatetruecolor(200, 200);
$transparent_color = imagecolorallocatealpha($image, 0, 0, 0, 100); // Set transparency level (0-127)

// Fill the image with a semi-transparent color
imagefilledrectangle($image, 0, 0, 200, 200, $transparent_color);

// Output the image with opacity
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);