PHP如何使用ImagickDraw annotation()函数(代码示例)

imagickdraw::annotation()函数是PHP中的内置函数, 用于在图像上绘制文本。
语法如下:

bool ImagickDraw::annotation( $x, $y, $text )

参数:此函数接受上述和以下描述的三个参数:
  • $x:此参数用于保存要绘制文本的x坐标的值。
  • $y:此参数用于保存要绘制文本的y坐标值。
  • $text:此参数用于保存要在图像上绘制的字符串值。
【PHP如何使用ImagickDraw annotation()函数(代码示例)】返回值:该函数不返回值。
下面的程序说明了imagickdraw ::注释()PHP中的功能:
程序1:
< ?php// Create an ImagickDraw Object $draw = new ImagickDraw(); // Set Fill Color $draw -> setFillColor( 'white' ); // Set FOnt Size $draw -> setFontSize(20); // Set Text $draw -> annotation(5, 75, "lsbin!" ); $draw -> annotation(150, 75, "sarthak_ishu11" ); // Create new Imagick Object $imagick = new Imagick(); $imagick -> newImage(300, 160, 'green' ); // Set Image Format $imagick -> setImageFormat( "png" ); $imagick -> drawImage( $draw ); header( "Content-Type: image/png" ); // Display Image on Screen echo $imagick -> getImageBlob(); ?>

输出如下:
PHP如何使用ImagickDraw annotation()函数(代码示例)

文章图片
程式2:
< ?php// Create an ImagickDraw Object $draw = new ImagickDraw(); // Set Stroke Opacity $draw -> setStrokeOpacity(1); // Set Stroke Color $draw -> setStrokeColor( 'Black' ); // Set Fill Color $draw -> setFillColor( 'Green' ); // Set Stroke Width $draw -> setStrokeWidth(3); // Define the points $points = [ [ 'x' => 40 * 5, 'y' => 10 * 5], [ 'x' => 20 * 5, 'y' => 20 * 5], [ 'x' => 70 * 5, 'y' => 50 * 5], [ 'x' => 40 * 5, 'y' => 10 * 5] ]; // Set the Font Size $draw -> setFontSize(50); // Set the font family $draw -> setFontFamily( 'Ubuntu-Mono' ); // Set the text to be added $draw -> annotation(30, 40, "lsbin" ); // Call Polyline Function $draw -> polyline( $points ); // Create an Imagick Object $image = new Imagick(); // Create new Image $image -> newImage(500, 300, 'white' ); // Set Image Format $image -> setImageFormat( "png" ); // Draw Image $image -> drawImage( $draw ); header( "Content-Type: image/png" ); // Display the output image echo $image -> getImageBlob(); ?>

输出如下:
PHP如何使用ImagickDraw annotation()函数(代码示例)

文章图片
程式3:
< ?php //Create a new Imagick object $imagick = new Imagick(); // Create a image on imagick object $imagick -> newImage(800, 250, 'white' ); // Create a new ImagickDraw object $draw = new ImagickDraw(); // Set the text properties $draw -> setFontSize(110); $draw -> setFillColor( 'green' ); // Apply the annotation() function $draw -> annotation(20, 120, 'lsbin' ); // Set the text properties $draw -> setFontSize(40); $draw -> setFillColor( 'black' ); // Apply the annotation() function $draw -> annotation(70, 200, 'A computer science portal for geeks' ); //Render the draw commands in the ImagickDraw object $imagick -> drawImage( $draw ); // Show the output $imagick -> setImageFormat( "png" ); header( "Content-Type: image/png" ); echo $imagick -> getImageBlob(); ?>

输出如下:
PHP如何使用ImagickDraw annotation()函数(代码示例)

文章图片
参考: http://php.net/manual/en/imagickdraw.annotation.php

    推荐阅读