Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
imagecolorallocatealpha() function in PHP
The imagecolorallocatealpha() function allocates a color for an image.
Syntax
imagecolorallocatealpha ( img, red, green, blue, alpha )
Parameters
img: Image resource created with imagecreatetruecolor().
red: Red color component
green: Green color component
blue: Blue color component
alpha: The transparency of image, with 0 indicating completely opaque, whereas 127 indicating completely transparent.
Return
The imagecolorallocatealpha() function returns a color identifier or FALSE if the allocation failed.
Example
The following is an example:
<?php
$img = imagecreatetruecolor(520, 350);
$bgcolor = imagecolorallocate($img, 50, 10, 255);
imagefill($img, 0, 0, $bgcolor);
$one = imagecolorallocatealpha($img, 50, 255, 0, 70);
$two = imagecolorallocatealpha($img, 255, 0, 255, 50);
$three = imagecolorallocatealpha($img, 150, 255, 0, 60);
$four = imagecolorallocatealpha($img, 200, 0, 255, 90);
imagefilledellipse($img, 200, 150, 150, 150, $one);
imagefilledellipse($img, 220, 150, 150, 150, $two);
imagefilledellipse($img, 240, 150, 150, 150, $three);
imagefilledellipse($img, 280, 150, 150, 150, $four);
header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
?>
Output
The following is the output:

Advertisements