PHP如何使用ImagickDraw point()函数?用法示例

2021年3月31日12:14:44 发表评论 593 次浏览

ImagickDraw::point()函数是PHP的Imagick库中的一个内置函数, 用于绘制点。此功能使用指定坐标处的当前笔触颜色和笔触粗细。

语法如下:

bool ImagickDraw::point( $x, $y )

参数:此函数接受上述和以下所述的两个参数:

  • $ x:此参数用于保存x坐标的值。
  • $ y:此参数用于保存y坐标的值。

返回值:成功时此函数返回TRUE。

下面的程序演示了PHP中的ImagickDraw::point()函数用法:

程序:

<?php
  
// Create an ImagickDraw object
$draw = new \ImagickDraw();
  
// Set the filled color
$draw ->setFillColor( 'red' );
  
// Use loop to draw 10000 points in given area
for ( $x = 0; $x < 10000; $x ++) {
     $draw ->point(rand(0, 300), rand(0, 300));
}
  
// Create an Imagick object
$imagick = new \Imagick();
  
// Set the new image size
$imagick ->newImage(300, 300, 'white' );
  
// Set the image format
$imagick ->setImageFormat( "png" );
  
// Function to draw the image
$imagick ->drawImage( $draw );
  
header( "Content-Type: image/png" );
  
// Display the output image
echo $imagick ->getImageBlob();
?>

输出如下:

PHP如何使用ImagickDraw point()函数?用法示例

参考: http://php.net/manual/en/imagickdraw.point.php


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: