imagesetpixel
Description
The imagesetpixel of Image for PHP set a single pixel.
Syntax
imagesetpixel( GdImage $image, int $x, int $y, int $color ): bool
Parameters
image
A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor().
x
x-coordinate.
y
y-coordinate.
color
A color identifier created with imagecolorallocate().
Return
Returns true on success or false on failure.
Examples
1 · return
<? $width = 100; $height = 100; $image = imagecreate($width, $height); $red = 255; $green = 255; $blue = 255; $color = imagecolorallocate($image, $red, $green, $blue); $x = 0; $y = 0; $return = imagesetpixel($image, $x, $y, $color); var_export($return);
true
2 · base64
<? $width = 100; $height = 100; $image = imagecreatetruecolor($width, $height); $red = 255; $green = 255; $blue = 255; $color = imagecolorallocate($image, $red, $green, $blue); $x = 50; $y = 50; imagesetpixel($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/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAO0lEQVR4nO3OMQEAAAgDoPUvPUN4eAgJSAAAAAAAAAAAAAAAAAAA4JG21wUAAAAAAAAAAAAAAAAAAHYGZzAC/so5nyEAAAAASUVORK5CYII="> </body> </html>
3 · base64 · random
<? $width = 100; $height = 100; $image = imagecreatetruecolor($width, $height); $red = 255; $green = 255; $blue = 255; $color = imagecolorallocate($image, $red, $green, $blue); for($i = 0; $i < 1000; ++$i) { $x = rand(0, $width); $y = rand(0, $height); imagesetpixel($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/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAE9klEQVR4nM1X2bbcMA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IZIq0mlG24xTgZ6dYybN8BCOj7j6uFf4xvPo8Zwo2jC3rlLHM0Zp91GxjEvxKTfDQ6vl7292e191bi4TwmFSB9/hR2TEmzjjQyuaSbw6g4mbM6/D/xen480j1FRpSwpyxNHQo18OyleJzoCIGzyD8x4757hhN2ikhjkPPf4aMqUvYM8Vrr7AhznQ/bx7kAG7rt6/xHilpL7sjNgW6WlcAWvL76SKfxRwbvywpHE2TE/3Yl8DQ3fMSBwqlwCQRdimppLfNbRXwtpSlW5Rw83UHfQEDt0FwI4pP4pIHltJesqUWw4RUrHuOUorqhDi3M5VvWDHYRgjd/uLgk8cAEw7ixlwFVRfP+jNiJa50VgJyYfimXi608Hzf67nkg3Qep/V979gZ+VZOduzDBcS7BbyhMAr0N1Nx3bU6UGRAyuv+2AqsyOEl3uk64XTKt0uCiS8oelFwUVffFtpF5/wMhLkBuJ3Q+8qhwHFlHGT7H7BlG4zDERcWqDp744WnEExmlnLYkR/EHnvFVQJvQ/WGjj730rrJXjWLq4zGO9vcrF8OAQLEvQGsal47VTXUe2MlSfe8GnNLYAmzudvjnNXCTiP55NrrZ1ZZA++AdLLfCcGX3HsAAAAABJRU5ErkJggg=="> </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
- imagesavealpha
- imagescale
- imagesetbrush
- imagesetclip
- imagesetinterpolation
- imagesetstyle
- imagesetthickness
- imagesettile
- imagestring
- imagestringup
- imagesx
- imagesy
- imagetruecolortopalette
- imagettfbbox
- imagettftext
- imagetypes
- imagewbmp
- imagewebp
- imagexbm
- iptcembed
- iptcparse