Open In App

PHP | Imagick getImageBackgroundColor() Function

Last Updated : 15 Nov, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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

Syntax:

ImagickPixel Imagick::getImageBackgroundColor( void )

Parameters: This function does not accept any parameters.

Exceptions: This function throws ImagickException on error.

Return Value: This function returns an ImagickPixel set to the background color of the image.

Below programs illustrate the Imagick::getImageBackgroundColor() function in PHP:

Program 1:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Get the Background Color
$imagickPixelColor = $imagick->getImageBackgroundColor();
  
// Get the Color from ImagickPixel
$color = $imagickPixelColor->getColorAsString();
  
echo $color;
?>


Output:

rgb(255, 255, 255) which is the default value.

Program 2:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Set the Background Color
$imagick->setImageBackgroundColor('orange');
  
// Get the Background Color
$imagickPixelColor = $imagick->getImageBackgroundColor();
  
// Get the Color from ImagickPixel
$color = $imagickPixelColor->getColorAsString();
  
echo $color;
?>


Output:

rgb(255, 165, 0)

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads