📜  PHP | Gmagick quantizeimage()函数

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

PHP | Gmagick quantizeimage()函数

Gmagick::quantizeimage()函数是PHP中的一个内置函数,用于分析参考图像中的颜色并选择固定数量的颜色来表示图像。这个函数的主要原因是在最小化处理时间的同时最小化输入和输出图像之间的色差。

句法:

Gmagick Gmagick::quantizeimage( int $numColors, int $colorspace,
          int $treeDepth, bool $dither, bool $measureError )

参数:此函数接受上述五个参数,如下所述:

  • $numColors:它指定颜色的数量。
  • $colorspace:它指定颜色空间。
  • $treeDepth:指定树的深度。
  • $dither:指定是否允许抖动。
  • $measureError:指定是否测量图像差异误差。

返回值:此函数在成功时返回 Gmagick 对象。

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

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

使用图像:

程序 1(量化图像):

quantizeimage(100, 8, 256, true, false);
  
// Output the image  
header('Content-type: image/png');  
echo $gmagick;  
?>

输出:

程序 2(量化绘图):

setFillColor('red');
   
// Function to draw rectangle
$draw->rectangle(0, 0, 800, 400);
   
// Set the fill color
$draw->setFillColor('white');
   
// Set the font size
$draw->setfontsize(50);
   
// Annotate a text
$draw->annotate(30, 100, 'GeeksforGeeks');
   
// Use of drawimage function
$gmagick->drawImage($draw);
  
// Quantize the image
$gmagick->quantizeimage(10, 8, 996, true, false);
  
// Output the image  
header('Content-type: image/png');  
echo $gmagick;  
?>

输出:

参考: https://www. PHP.net/manual/en/gmagick.quantizeimage。 PHP