imagealphablending
Description
The imagealphablending of Image for PHP set the blending mode for an image.
Syntax
imagealphablending( GdImage $image, bool $enable ): bool
Parameters
image
A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor().
enable
Whether to enable the blending mode or not. On true color images the default value is true otherwise the default value is false.
Return
Returns true on success or false on failure.
Examples
1 · return
<? $width = 100; $height = 100; $image = imagecreate($width, $height); $enable = true; $return = imagealphablending($image, $enable); var_export($return);
true
2 · base64 · imagecreate · enable · false
<? $width = 100; $height = 100; $image = imagecreate($width, $height); $enable = false; imagealphablending($image, $enable); $red = 0; $green = 0; $blue = 0; $background = imagecolorallocate($image, $red, $green, $blue); $red = 255; $green = 0; $blue = 0; $alpha = 64; $color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); $x1 = 0; $y1 = 0; $x2 = 75; $y2 = 75; imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color); $red = 0; $green = 0; $blue = 255; $alpha = 64; $color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); $x1 = 25; $y1 = 25; $x2 = 100; $y2 = 100; imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color); 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,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAgMAAAANjH3HAAAACVBMVEX/AAAAAP8AAAAUKeN6AAAAAnRSTlN+fnCSxXsAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAwSURBVEiJY2DABKvAAIvEqMyoDK1lREMxwKjMqMyozKjMqAySDKTQnDoqMypDDxkAyfmVwCKRv1gAAAAASUVORK5CYII="> </body> </html>
3 · base64 · imagecreate · enable · true
<? $width = 100; $height = 100; $image = imagecreate($width, $height); $enable = true; imagealphablending($image, $enable); $red = 0; $green = 0; $blue = 0; $background = imagecolorallocate($image, $red, $green, $blue); $red = 255; $green = 0; $blue = 0; $alpha = 64; $color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); $x1 = 0; $y1 = 0; $x2 = 75; $y2 = 75; imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color); $red = 0; $green = 0; $blue = 255; $alpha = 64; $color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); $x1 = 25; $y1 = 25; $x2 = 100; $y2 = 100; imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color); 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,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAgMAAAANjH3HAAAACVBMVEX/AAAAAP8AAAAUKeN6AAAAAnRSTlN+fnCSxXsAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAwSURBVEiJY2DABKvAAIvEqMyoDK1lREMxwKjMqMyozKjMqAySDKTQnDoqMypDDxkAyfmVwCKRv1gAAAAASUVORK5CYII="> </body> </html>
4 · base64 · imagecreatetruecolor · enable · false
<? $width = 100; $height = 100; $image = imagecreatetruecolor($width, $height); $enable = false; imagealphablending($image, $enable); $red = 255; $green = 0; $blue = 0; $alpha = 64; $color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); $x1 = 0; $y1 = 0; $x2 = 75; $y2 = 75; imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color); $red = 0; $green = 0; $blue = 255; $alpha = 64; $color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); $x1 = 25; $y1 = 25; $x2 = 100; $y2 = 100; imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color); 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,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA+UlEQVR4nO3csQ2AMBAEQYzov2UIEAWs9JGZKeCClTPLXvexvzW0cw7t/IJYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgVjBNbi1js1vbJ2sQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxg6tvhl2e/fMQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKHkkmA8i9Q95eAAAAAElFTkSuQmCC"> </body> </html>
5 · base64 · imagecreatetruecolor · enable · true
<? $width = 100; $height = 100; $image = imagecreatetruecolor($width, $height); $enable = true; imagealphablending($image, $enable); $red = 255; $green = 0; $blue = 0; $alpha = 64; $color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); $x1 = 0; $y1 = 0; $x2 = 75; $y2 = 75; imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color); $red = 0; $green = 0; $blue = 255; $alpha = 64; $color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); $x1 = 25; $y1 = 25; $x2 = 100; $y2 = 100; imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color); 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,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA+klEQVR4nO3bsQ2AMBAEQRtRNwGd0RkRBazkyMwUcMHqM8vzGvu7F+0ci3Z+QaxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArOBcuPWMzV9sXVYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgVjCXrvn2y0esQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECs4AVnoAOGxQbBjwAAAABJRU5ErkJggg=="> </body> </html>
Links
Image
- gd_info
- getimagesize
- getimagesizefromstring
- image_type_to_extension
- image_type_to_mime_type
- imageaffine
- imageaffinematrixconcat
- imageaffinematrixget
- imageantialias
- imagearc
- imageavif
- imagebmp
- imagechar
- imagecharup
- imagecolorallocate
- imagecolorallocatealpha
- 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