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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lljMyOVbCh4+eU6hv3ZmZ+pT0F5BFc55QeCgPsoVrpieZI+BV5pBeTf4F42dJvXdB1pMcy6U9vEW1Fe5izsI1xDZyEXqDbtUjPxTwEe04tr5e1VZE0LXIGh2Zhd4FTt8fbuyzLT8I29ZldkG0KOBrLm0kjf0PGxd7wPLrfCt6m3hu4pxP4hSpFTpvrespxhZq/0ByepicQV1gV4KvJoWNmPP2QzgeTni+U5kKWJT7Ow0wo7/h4JzthYP+Fq4O7kiUi/HyCgOGpktLwpQBQ7pTRlZYxUbGAPuEFuGszaP52ORvgwtCuqQAQ+QAw3vdwt94wTkxLP6cu01I9GfKUaGXBkunpcnOmXFhoMMHbzV0+pD/hTuXB+aJQOLCWexoep80BM1Sl3mDXFJ2jO3k3lVbBfHGRvKlo5xFYXJnRwfZBUbWOvZ8Dbz22W4LASC5+VcKyvUYBdZ7Rr/wO1aTtoBIR25lBDKJjd4ka8FLn19Mk6fYNDKJODs3oJvj5IJkL7Hb2UKNgOnrm2bemdE3AOLH/ZBYzeNQrBw3i4uHhbWMVs0qDe44Y0SN/4TPIQkrQjjTeKFc38y7q01s4adStTQ1Ap8c02xFW5f/9VxI7gU5IElCposuudbq/Q1I6zCepiGToMsX7buqSP8/DpHewSM9T+59PmT8DckywAAAABJRU5ErkJggg==">
</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