imagesetpixel() PHP में एक अंतर्निहित फ़ंक्शन है जिसका उपयोग सूचीबद्ध कोऑर्डिनेट पर सिंगल पिक्सेल सेट करने के लिए किया जाता है।
सिंटैक्स
bool imagesetpixel(resource $image, int $x, int $y, int $color)
पैरामीटर्स
imagesetpixel() चार पैरामीटर्स स्वीकार करता है: $image, $x, $y और $color।
$image - काम करने के लिए इमेज रिसोर्स निर्दिष्ट करता है।
$x - पिक्सेल के x-कोऑर्डिनेट को निर्दिष्ट करता है।
$y - पिक्सेल के y-कोऑर्डिनेट को निर्दिष्ट करता है।
$color - पिक्सेल के रंग को निर्दिष्ट करता है।
रिटर्न वैल्यूज़
imagesetpixel() सफलता पर True और विफलता पर False लौटाता है।
उदाहरण 1
<?php
// imagecreatefromjpeg() फ़ंक्शन का उपयोग करके PNG इमेज लोड करें
$img = imagecreatefromjpeg('C:\xampp\htdocs\test\29.jpg');
// imagesetpixel() फ़ंक्शन का उपयोग करके लाइन खींचें
$blue = imagecolorallocate($img, 255, 255, 0);
for ($i = 0; $i < 1000; $i++) {
imagesetpixel($img, $i, 100, $blue);
}
// ब्राउज़र को आउटपुट इमेज दिखाएं
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);
?>
आउटपुट
