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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T7dJcyVGXA3cxPFlrRrqMmSM1oqwj/IqSHwekfOLQj8rYqVW4WOE5iVJyjXMHM/DdCv6iJjxstemX+uGheE+BdtVk50oIlyQ2p0MDIAwhffzlKaydxW3rbvDVRmPbdu7w6lQMIOmp+VLn2FampJ+CBj9IDWqn57bEEASmnILRQ+enCXd3CYYKBNsoCRQxp3EThi7czXZenmXniXC1vLMlk0gjSD5aljpgO10UraROtnXSdF1Xj8gfSOG1q4jPMWKBhJ5E1LjQkkM3rS9tlUVdJmtZRsThhRRUUsW1xjHKFzpsDTg6XKt/g5mlffqYpgmO5/7lhavjRSLOkWSRt2bTZJQI32Sh4fVL4cRRpb7RM3nZMHisY+VO2VpuuUQ46FXMSHF7GtbhEWusBoK4TxRAfbo2u4GUslS7g20L6bWLK3T9DinrPdx80GSzBv7eBqMq9Zbgp6LP2XUV6JR3QkyxY2PlSTqe5L5V5K0QS5QJdSIEKbdeFGIcnDzwxA+YmvUjNwsmQ7qExXFukNDk0+2nwAM1ZC4KB8S01GexwL+ikJDV3mo3CdUgvtMKYKBVQ8s8hQR1bnXfJ7sjb32qVswCotUO+eRKbtHRzoXPdoKH8QC1sARo4Y72C1hl56Wod97bAAAAAElFTkSuQmCC">
</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