PHP | ImagickPixel setIndex() Function Last Updated : 14 Jan, 2020 Comments Improve Suggest changes Like Article Like Report The ImagickPixel::setIndex() function is an inbuilt function in PHP which is used to set the colormap index of the pixel. Syntax: bool ImagickPixel::setIndex( int $index ) Parameters: This function accepts a single parameter $index which holds the index to be set. Return Value: This function returns TRUE on success. Below programs illustrate the ImagickPixel::setIndex() function in PHP: Program 1: This program set and return the index for a single pixel. php <?php // Create a new imagickPixel object $imagickPixel = new ImagickPixel(); // Set the index $imagickPixel->setIndex(15); // Get the index $index = $imagickPixel->getIndex(); echo $index; ?> Output: 15 Program 2: This program returns the index value of an image. php <?php // Create a new imagick object $imagick = new Imagick( 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); // Get the pixel iterator to iterate through each pixel $imageIterator = $imagick->getPixelIterator(); $i = 0; // Loop through pixel rows foreach ($imageIterator as $row => $pixels) { foreach ($pixels as $column => $pixel) { // Set the index $pixel->setIndex($i); echo $pixel->getIndex() . '<br>'; $i++; } // Sync the iterator after each iteration $imageIterator->syncIterator(); } ?> Output: 0 1 2 3 . . . Reference: https://www.php.net/manual/en/imagickpixel.setindex.php Create Quiz Comment G gurrrung Follow 0 Improve G gurrrung Follow 0 Improve Article Tags : Web Technologies PHP PHP-function PHP-Imagick Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like