imagesavealpha
Description
The imagesavealpha of Image for PHP whether to retain full alpha channel information when saving images.
Syntax
imagesavealpha( GdImage $image, bool $enable ): bool
Parameters
image
A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor().
enable
Whether to save the alpha channel or not. Defaults to false.
Return
Returns true on success or false on failure.
Examples
1 · return
<? $width = 100; $height = 100; $image = imagecreate($width, $height); $enable = true; $return = imagesavealpha($image, $enable); var_export($return);
true
2 · base64 · enable · false
<? $width = 100; $height = 100; $image = imagecreatetruecolor($width, $height); $enable = false; imagesavealpha($image, $enable); $red = 0; $green = 0; $blue = 0; $alpha = 64; $color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); $x = 0; $y = 0; imagefill($image, $x, $y, $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/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAANElEQVR4nO3BAQ0AAADCoPdPbQ43oAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAfgx1lAABqFDyOQAAAABJRU5ErkJggg=="> </body> </html>
3 · base64 · enable · true
<? $width = 100; $height = 100; $image = imagecreatetruecolor($width, $height); $enable = true; imagesavealpha($image, $enable); $red = 0; $green = 0; $blue = 0; $alpha = 64; $color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha); $x = 0; $y = 0; imagefill($image, $x, $y, $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,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABAElEQVR4nO3RQQ0AIBDAsAPhaOeNAvZoFSzZmpkzZOzfAbwMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEkxpAYQ2IMiTEk5gLrigFGs/uyPgAAAABJRU5ErkJggg=="> </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
- 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
- imagescale
- imagesetbrush
- imagesetclip
- imagesetinterpolation
- imagesetpixel
- imagesetstyle
- imagesetthickness
- imagesettile
- imagestring
- imagestringup
- imagesx
- imagesy
- imagetruecolortopalette
- imagettfbbox
- imagettftext
- imagetypes
- imagewbmp
- imagewebp
- imagexbm
- iptcembed
- iptcparse