imagecolorallocatealpha
Description
The imagecolorallocatealpha of Image for PHP allocate a color for an image.
Syntax
imagecolorallocatealpha( GdImage $image, int $red, int $green, int $blue, int $alpha ): int|false
Parameters
image
A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor().
red
Value of red component.
green
Value of green component.
blue
Value of blue component.
alpha
A value between 0 and 127. 0 is completely opaque and 127 is completely transparent.
Return
A color identifier or false if the allocation failed.
Warning: This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Use the === operator for testing the return value of this function.
Examples
1 · red green blue · decimal
<? $width = 100; $height = 100; $image = imagecreate($width, $height); $red = 255; $green = 255; $blue = 255; $alpha = 64; $return = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); echo $return;
0
2 · red green blue · hexadecimal
<? $width = 100; $height = 100; $image = imagecreate($width, $height); $red = 0xff; $green = 0xff; $blue = 0xff; $alpha = 64; $return = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); echo $return;
0
3 · return
<? $width = 100; $height = 100; $image = imagecreate($width, $height); $red = 255; $green = 255; $blue = 255; $alpha = 64; $background = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); $red = 255; $green = 0; $blue = 0; $alpha = 64; $r = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); $red = 0; $green = 255; $blue = 0; $alpha = 64; $g = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); $red = 0; $green = 0; $blue = 255; $alpha = 64; $b = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); echo $background . $r . $g . $b;
0123
4 · base64
<? $width = 100; $height = 100; $image = imagecreatetruecolor($width, $height); $enable = true; imagesavealpha($image, $enable); $red = 255; $green = 255; $blue = 255; $alpha = 64; $background = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); $x = 0; $y = 0; imagefill($image, $x, $y, $background); $red = 255; $green = 0; $blue = 0; $alpha = 64; $r = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); $x1 = 0; $y1 = 0; $x2 = 50; $y2 = 50; imagefilledrectangle($image, $x1, $y1, $x2, $y2, $r); $red = 0; $green = 255; $blue = 0; $alpha = 64; $g = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); $x1 = 25; $y1 = 25; $x2 = 75; $y2 = 75; imagefilledrectangle($image, $x1, $y1, $x2, $y2, $g); $red = 0; $green = 0; $blue = 255; $alpha = 64; $b = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); $x1 = 50; $y1 = 50; $x2 = 100; $y2 = 100; imagefilledrectangle($image, $x1, $y1, $x2, $y2, $b); ob_start(); imagepng($image); $output = ob_get_clean(); echo '<!doctype html> <html> <body> <img src="data:image/png;base64,' . base64_encode($output) . '"> </body> </html>';
<!doctype html> <html> <body> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABX0lEQVR4nO3csU0DQRBA0TNyATSA5FbowVcABRCS0goFXAGEZKS04ZQKjpicXX+s9xqYPX3tRaM97Ofzx3Irtu3ff8vdtQ/Ab4LECBIjSIwgMYLECBIjSIwgMYLECBIjSIwgMYLECBIjSIwgMYLECBIjSIwgMYLECBIjSMxxxpDnp6/TjDmXZX0cPWNbxi7juSExgsQIEiNIjCAxgsQIEiNIjCAxgsQIEiNIjCAxgsQIEiNIjCAxgsQIEiNIjCAxgsQIEiNIzJRFuRk+317uv98fTqPnrJdl6DLeccazeDM2CmfEmMEvK0aQGEFiBIkRJEaQGEFiBIkRJEaQGEFiBIkRJEaQGEFiBIkRJEaQGEFiBIkRJEaQGEFiBIk57Pv+eu1D/IV1HbtROIsbEiNIjCAxgsQIEiNIjCAxgsQIEiNIjCAxgsQIEiNIjCAxgsQIEiNIjCAxgsQIEiNIjCAxP77GGcNMNCzSAAAAAElFTkSuQmCC"> </body> </html>
Links
Image
- gd_info
- getimagesize
- getimagesizefromstring
- image_type_to_extension
- image_type_to_mime_type
- imageaffine
- imageaffinematrixconcat
- imageaffinematrixget
- imagealphablending
- imageantialias
- imagearc
- imageavif
- imagebmp
- imagechar
- imagecharup
- imagecolorallocate
- imagecolorat
- imagecolorclosest
- imagecolorclosestalpha
- imagecolorclosesthwb
- imagecolordeallocate
- imagecolorexact
- imagecolorexactalpha
- imagecolormatch
- imagecolorresolve
- imagecolorresolvealpha
- imagecolorset
- imagecolorsforindex
- imagecolorstotal
- imagecolortransparent
- imageconvolution
- imagecopy
- imagecopymerge
- imagecopymergegray
- imagecopyresampled
- imagecopyresized
- imagecreate
- imagecreatefromavif
- imagecreatefrombmp
- imagecreatefromgif
- imagecreatefromjpeg
- imagecreatefrompng
- imagecreatefromstring
- imagecreatefromtga
- imagecreatefromwbmp
- imagecreatefromwebp
- imagecreatefromxbm
- imagecreatefromxpm
- imagecreatetruecolor
- imagecrop
- imagecropauto
- imagedashedline
- imagedestroy
- imageellipse
- imagefill
- imagefilledarc
- imagefilledellipse
- imagefilledpolygon
- imagefilledrectangle
- imagefilltoborder
- imagefilter
- imageflip
- imagefontheight
- imagefontwidth
- imageftbbox
- imagefttext
- imagegammacorrect
- imagegetclip
- imagegetinterpolation
- imagegif
- imageinterlace
- imageistruecolor
- imagejpeg
- imagelayereffect
- imageline
- imageloadfont
- imageopenpolygon
- imagepalettecopy
- imagepalettetotruecolor
- imagepng
- imagepolygon
- imagerectangle
- imageresolution
- imagerotate
- imagesavealpha
- imagescale
- imagesetbrush
- imagesetclip
- imagesetinterpolation
- imagesetpixel
- imagesetstyle
- imagesetthickness
- imagesettile
- imagestring
- imagestringup
- imagesx
- imagesy
- imagetruecolortopalette
- imagettfbbox
- imagettftext
- imagetypes
- imagewbmp
- imagewebp
- imagexbm
- iptcembed
- iptcparse