Imagick::getImageBackgroundColor()函数是PHP中的内置函数,用于获取图像背景色。
用法:
ImagickPixel Imagick::getImageBackgroundColor( void )
参数:该函数不接受任何参数。
异常:该函数在错误时引发ImagickException。
返回值:此函数返回一个ImagickPixel设置为图像的背景色。
以下示例程序旨在说明PHP中的Imagick::getImageBackgroundColor()函数:
示例1:
// Create a new imagick object
$imagick = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
// Get the Background Color
$imagickPixelColor = $imagick->getImageBackgroundColor();
// Get the Color from ImagickPixel
$color = $imagickPixelColor->getColorAsString();
echo $color;
?>
输出:
rgb(255, 255, 255) which is the default value.
示例2:
// Create a new imagick object
$imagick = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
// Set the Background Color
$imagick->setImageBackgroundColor('orange');
// Get the Background Color
$imagickPixelColor = $imagick->getImageBackgroundColor();
// Get the Color from ImagickPixel
$color = $imagickPixelColor->getColorAsString();
echo $color;
?>
输出:
rgb(255, 165, 0)