Friday, October 10, 2025
HomeLanguagesPHP | ImagickPixel getColorAsString() Function

PHP | ImagickPixel getColorAsString() Function

The ImagickPixel::getColorAsString() function is an inbuilt function in PHP which is used to get the color of the ImagickPixel object as a string.

Syntax:

string ImagickPixel::getColorAsString( void )

Parameters: This function doesn’t accepts any parameters.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

Below programs illustrate the ImagickPixel::getColorAsString() function in PHP:

Program 1:




<?php
  
// Create a new imagickPixel object
$imagickPixel = new ImagickPixel();
  
// Get the color as string
$color = $imagickPixel->getColorAsString();
echo $color;
?>


Output:

srgb(0, 0, 0) // Which is the default color

Program 2:




<?php
  
// Create a new imagick object
$imagickPixel = new ImagickPixel();
  
// Set the color
$imagickPixel->setColor('#5b7db3');
  
// Get the color
$color = $imagickPixel->getColorAsString();
echo $color;
?>


Output:

srgb(91, 125, 179)

Reference: https://www.php.net/manual/en/imagickpixel.getcolorasstring.php

RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS