📜  PHP | Gmagick addnoiseimage()函数

📅  最后修改于: 2022-05-13 01:56:47.004000             🧑  作者: Mango

PHP | Gmagick addnoiseimage()函数

Gmagick::addnoiseimage()函数是PHP中的一个内置函数,用于在给定图像中添加噪声。噪声的强度取决于噪声常数和通道类型。图像噪声是图像中亮度和对比度的随机变化。

句法:

Gmagick Gmagick::addnoiseimage ( $noise_type )

参数:此函数接受单个参数$noise_type用于设置噪声类型。

返回值:此函数返回带有噪声的 Gmagick 对象。

错误/异常:此函数在错误时抛出 GmagickException。

下面的程序说明了PHP中的Gmagick::addnoiseimage()函数:

原图1:

方案一:

PHP
addnoiseimage(2);
 
header('Content-type: image/png');
   
// Output the image
echo $gmagick;
?>


PHP
setStrokeOpacity(1);
$draw->setStrokeColor('Red');
$draw->setFillColor('Green');
   
// Set the width and height of image
$draw->setStrokeWidth(7);
$draw->setFontSize(72);
    
// Function to draw circle 
$draw->circle(250, 250, 100, 150);
  
$gmagick = new Gmagick();
$gmagick->newImage(500, 500, 'White');
$gmagick->setImageFormat("png");
$gmagick->drawImage($draw);
 
// Add noise in the image
$gmagick->addnoiseimage(5);
  
// Display the output image
header("Content-Type: image/png");
echo $gmagick->getImageBlob();
?>


输出:

方案二:

PHP

setStrokeOpacity(1);
$draw->setStrokeColor('Red');
$draw->setFillColor('Green');
   
// Set the width and height of image
$draw->setStrokeWidth(7);
$draw->setFontSize(72);
    
// Function to draw circle 
$draw->circle(250, 250, 100, 150);
  
$gmagick = new Gmagick();
$gmagick->newImage(500, 500, 'White');
$gmagick->setImageFormat("png");
$gmagick->drawImage($draw);
 
// Add noise in the image
$gmagick->addnoiseimage(5);
  
// Display the output image
header("Content-Type: image/png");
echo $gmagick->getImageBlob();
?>

输出:

参考: http: PHP。 PHP