इमेजसेटपिक्सेल () PHP में एक इनबिल्ट फ़ंक्शन है जिसका उपयोग सूचीबद्ध निर्देशांक पर एकल पिक्सेल सेट करने के लिए किया जाता है।
सिंटैक्स
bool imagesetpixel(resource $image, int $x, int $y, int $color)
पैरामीटर
इमेजसेटपिक्सेल () चार पैरामीटर स्वीकार करता है:$छवि , $x , $y और $रंग ।
-
$छवि - काम करने के लिए छवि संसाधन निर्दिष्ट करता है।
-
$x − पिक्सेल के x-निर्देशांक को निर्दिष्ट करता है।
-
$y − पिक्सेल के y-निर्देशांक को निर्दिष्ट करता है।
-
$रंग - पिक्सेल का रंग निर्दिष्ट करता है।
रिटर्न वैल्यू -
इमेजसेटपिक्सेल () सफलता पर सही और असफलता पर गलत लौटाता है।
उदाहरण 1
<?php
// Load the png image using imagecreatefromjpeg() function
$img = imagecreatefromjpeg('C:\xampp\htdocs\test\29.jpg');
// Draw the line using imagesetpixel() function
$blue = imagecolorallocate($img, 255, 255, 0);
for ($i = 0; $i < 1000; $i++) {
imagesetpixel($img, $i, 100, $blue);
}
// Show the output image to the browser
header('Content-type: image/png');
imagepng($img);
?> आउटपुट

उदाहरण 2
<?php
$x = 700;
$y = 300;
$gd = imagecreatetruecolor($x, $y);
$corners[0] = array('x' => 100, 'y' => 10);
$corners[1] = array('x' => 0, 'y' => 170);
$corners[2] = array('x' => 190, 'y' => 170);
$blue = imagecolorallocate($gd, 255, 0, 0);
for ($i = 0; $i < 100000; $i++) {
imagesetpixel($gd, round($x),round($y), $blue);
$a = rand(0, 2);
$x = ($x + $corners[$a]['x']) / 2;
$y = ($y + $corners[$a]['y']) / 2;
}
header('Content-Type: image/png');
imagepng($gd);
?> आउटपुट
