imagecolorset
Description
The imagecolorset of Image for PHP set the color for the specified palette index.
Syntax
imagecolorset( GdImage $image, int $color, int $red, int $green, int $blue, int $alpha = 0 ): ?false
Parameters
image
A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor().
color
An index in the palette.
red
Value of red component.
green
Value of green component.
blue
Value of blue component.
alpha
Value of alpha component.
Return
The function returns null on success, or false on failure.
Examples
1 · image color red green blue
<? $width = 100; $height = 100; $image = imagecreate($width, $height); $red = 0; $green = 0; $blue = 0; imagecolorallocate($image, $red, $green, $blue); $x = 0; $y = 0; $color = imagecolorat($image, $x, $y); $red = 255; $green = 255; $blue = 255; $return = imagecolorset($image, $color, $red, $green, $blue); var_export($return); ?>
NULL
2 · alpha
<? $width = 100; $height = 100; $image = imagecreate($width, $height); $red = 0; $green = 0; $blue = 0; imagecolorallocate($image, $red, $green, $blue); $x = 0; $y = 0; $color = imagecolorat($image, $x, $y); $red = 255; $green = 255; $blue = 255; $alpha = 64; $return = imagecolorset($image, $color, $red, $green, $blue, $alpha); var_export($return); ?>
NULL
3 · base64
<? $width = 100; $height = 100; $image = imagecreate($width, $height); $red = 0; $green = 0; $blue = 0; imagecolorallocate($image, $red, $green, $blue); $x = 0; $y = 0; $color = imagecolorat($image, $x, $y); $red = 255; $green = 255; $blue = 255; $alpha = 64; imagecolorset($image, $color, $red, $green, $blue, $alpha); 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,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkAQMAAABKLAcXAAAAA1BMVEX///+nxBvIAAAAAXRSTlN+91uEXQAAAAlwSFlzAAAOxAAADsQBlSsOGwAAABRJREFUOI1jYBgFo2AUjIJRQE8AAAV4AAH5pV7HAAAAAElFTkSuQmCC"> </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
- 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