📜  PHP | imagickdraw setFont()函数

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

PHP | imagickdraw setFont()函数

ImagickDraw::setFont()函数是PHP中的一个内置函数,用于设置在使用文本注释时使用的完全指定的字体。

句法:

bool ImagickDraw::setFont( $font_name )

参数:此函数接受单个参数$font_name ,该参数用于将字体名称的值保存为字符串。

返回值:此函数在成功时返回 True。

下面的程序说明了PHP中的ImagickDraw::setFont()函数

方案一:

setFillColor('green');
      
// Set the Font Size
$draw->setFontSize(40);
   
// Set the Font Style
$draw->setFont("./font/IndieFlower.ttf");
  
// Set the text to be added
$draw->annotation(50, 50, "GeeksForGeeks");
   
// Set the Font Style
$draw->setFont("./font/DancingScript-Regular.ttf");
  
// Set the text to be added
$draw->annotation(10, 100, "A Computer Science Portal For Geeks!");
   
// Set the Font Style
$draw->setFont("./font/NanumGothic-Regular.ttf");
  
// Set the text to be added
$draw->annotation(50, 150, "@sarthak_ishu11");
  
// Create new Imagick object  
$imagick = new Imagick();
  
// Set the image dimension
$imagick->newImage(560, 200, 'white');
  
// Set the image format
$imagick->setImageFormat("png");
  
// Draw the image
$imagick->drawImage($draw);
header("Content-Type: image/png");
  
// Display the image
echo $imagick->getImageBlob();
?>

输出:
设置字体

方案二:

setFontSize(40);
  
// Set the image filled color
$draw->setFillColor('green');
  
// Draw the rectangle
$draw->rectangle(30, 100, 300, 300);
  
// Set the image filled color
$draw->setFillColor('black');
  
// Set the font style
$draw->setFont("./font/IndieFlower.ttf");
  
// Set the text to be added
$draw->annotation(35, 280, "GeeksForGeeks");
   
// Create new Imagick object
$imagick = new Imagick();
  
// Set the image dimensions
$imagick->newImage(330, 330, 'white');
  
// Set the image format
$imagick->setImageFormat("png");
  
// Draw the image 
$imagick->drawImage($draw);
header("Content-Type: image/png");
  
// Display the image
echo $imagick->getImageBlob();
?>

输出:
设置字体

参考: http: PHP。 PHP