Related Articles

Related Articles

PHP | Gmagick getimagebackgroundcolor() Function
  • Last Updated : 17 Jan, 2020

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

rgb(47802, 22873, 22873)

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :