imagesetpixel
Description
The imagesetpixel of Image for PHP set a single pixel.
Syntax
imagesetpixel(
GdImage $image,
int $x,
int $y,
int $color
): boolParameters
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/gAIDAAAAC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79HJVtN7k9UxyVCnSOlJmRuqHTDQG6vnZQ/h3KcKMCTvdAhfuJ2BM+Nb+n0X3oKdhyZhQ67+N4ZoFv1HF5fGSgyO/ppwH6p/TlV1naBGeQxjbAj39AaizYWuEmVDKIZqATncKur6CjHCLlP3rTk6gT0kH0OZPX7P0+/IBlBc4Rn+nEDVnbsQgg8+BWERQwjWeSp7pMQOhpzbOgg/hHRk14CWncsBYOtxPK7H2RhSB10Tq8Wk0cQcP1LTdXfXYR+xIAJeRWcV9yABw36a1rwywMaaXdJgytuqF48mVEaj8QdOoyBF9uxf5A3MDLiliAsktJH2v10+BCB1zMDJGW8fnUIRH2OKFAEMigPtZs1pEYgm9bPbXE3XDtWoA+TU2KzBLlSvwGQdlPpPC2NzXOrzNQddT8fL3QdLHZ1YfJlpXhzCglT3UuHVfbXUwOpQUVRI8SgQ/qmrLrQVA5STMjbXiml7O0S/GjlR5yO3Xd4VU5NnKkWDK89Dyuf8lq6YqW5VgIIEc/L+1TMnKDsp9GeZYlByPirbrCkwxIsUnEQ8i29XWsZki98CqBZR1EqOHoDAck4X+DHL3PR8eLSgAAAABJRU5ErkJggg==">
</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