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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5cM1fTEKFmc0xV2miNJtBFvEljaPKtPyK7i+4YWzIVXnKE+T7k4003Ir2snz87Dlrd1dubBH2Lg5OYZpJwfleKkdrTp1fBdutw/V5LtSqlEDkHCNew8dXuInkDCf2mJUXXzh3VOFpAYGI2OlvC39y7nFskn9t7f4+2rkOtyPGWNI2tff6KW15IK3cMQB2zo061678NzvHGkWr1pby84HvlMragctHeGbXTVCFT87Rymq1bU1uvvn9fN8strN/N9ia9Yzoy753qTeUGnANvv6/0kYCpmYMWiMSXaUJ6VxMwzoOi1HBfCSWUVs4+A47EjZq+E0PGXZujQMjrtEKJq0AYvdBWNWC3bnzDa6GyQmSCIwYn8lc/DDS+10aG3DvbX2Nj15E/Z/jYP+qT3B+HZccqpfsdm4MECREcQIenz0o3cffua5bW7TVaX/B9curuY/XfJi/blSZNXdfu75T2mfPcCXoXftW3dfcvgkONIc3dHQ3hZqryTV5DVK5jK3y00hFSECJgN4IXXcjOx0yL4HzcW1kQGI5sv9QxIUJmBAEDeLZwCO9yzRetXd/XrSKEEcHmQ1c8yLynfNdoB6rmJz2HKpR1EyHWV1vfRG999ODrNSkfsMcfAGYk1K4/Mz8LkGLh3nAAAAAASUVORK5CYII=">
</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