Monday, November 17, 2025
HomeLanguagesPHP | Gmagick getimagebackgroundcolor() Function

PHP | Gmagick getimagebackgroundcolor() Function

The Gmagick::getimagebackgroundcolor() function is an inbuilt function in PHP which is used to get the image background color.

Syntax:

Gmagickpixel Gmagick::getimagebackgroundcolor( void )

Parameters: This function doesn’t accept any parameter.

Return Value: This function returns an Gmagickpixel value containing the color.

Exceptions: This function throws GmagickException on error.

Used Image: To capture the canvas area.

Below given programs illustrate the Gmagick::getimagebackgroundcolor() function in PHP:

Program 1:




<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick('neveropen.png');
  
// Get the background color
$color = $gmagick->getimagebackgroundcolor();
print("<pre>".print_r($color->getcolor(), true)."</pre>");
?>  


Output:

rgb(65535, 65535, 65535)  // Which is the default image background color.

Program 2:




<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick('neveropen.png');
  
// Set the background color
$gmagick->setimagebackgroundcolor('#ba5959');
  
// Get the background color
$color = $gmagick->getimagebackgroundcolor();
print("<pre>".print_r($color->getcolor(), true)."</pre>");
?>


Output:

rgb(47802, 22873, 22873)

Reference: https://www.php.net/manual/en/gmagick.getimagebackgroundcolor.php

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32402 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6772 POSTS0 COMMENTS
Nicole Veronica
11920 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11991 POSTS0 COMMENTS
Shaida Kate Naidoo
6899 POSTS0 COMMENTS
Ted Musemwa
7155 POSTS0 COMMENTS
Thapelo Manthata
6852 POSTS0 COMMENTS
Umr Jansen
6843 POSTS0 COMMENTS