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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EgwkkKsZ4aY4dlWiDoEtIyn0iluCSKO6Dcp1VD5JoVQIpbZviRTsPQe8apZT9xgErQ/ktmqBvlQ8a2ubIDMSK6y2NRJaZDAIYrZUn2DtiO2G2tHbM9KksTw+pbE37WxOOciS+abARvTFK5jOGlGmaI2mK5YQul5N6F6ajB0JIc4RQqiQb1Bq+iVtHIMsMO8y9LsqgfFKh6hR014fl6mE98glgLgliCLunDcKfkpHPh5s8FU3lDN5Z09tiJuQ4f39nEYcz9zSAhzVSu4TSKKgLSHVawMSOu4XlWCWyJv9TtMqm3K7fiRNxZWQ3lOlKPNXHYhgl2nDIngXvErwm8uJ9KXF7TDZJ/urpoxbqWtKoNxyfWsVdYIA58jD6AWeIgIW6UMlSvo29ezEMkUeqRDko2ROC+kKh5LRUDxhu1U1/++PX8P4fOhiEWmlD2OFFENw3qeyeSStg6Iwr5rmA7/7Okjpl7HHD+Zpi1RVmH75vowXMsmKTkj/kkencLykilzBE/SLuJDgyIARcQWaPZjZWcyDxudGWE09PH6syoR3FpkHp9+aHziVYglGVjGeBBqFI1k096ta4egB+iRRDPQ+/iYCgLNfyseieVf7Ax4/0roHa3mYAAAAAElFTkSuQmCC">
</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