Imagick::setFont()函數是PHP中的内置函數,用于設定字型。
用法:
bool Imagick::setFont( string $font )
參數:該函數接受單個參數$font,該參數儲存字型檔案的名稱。
傳回值:成功時此函數傳回TRUE。
擴充程式:為此功能需要安裝GD擴充程式。
以下示例程式旨在說明PHP中的Imagick::getFont()函數:
程式1:
// Create a new imagick object
$imagick = new Imagick();
// Use setFont() function to set the
// font using .ttf font file. The .ttf
// file is placed in same folder
$imagick->setFont('Windsong.ttf');
// Write a caption in image format
$imagick->newPseudoImage(800, 350, "caption:GeekforGeeks");
// Show the output
$imagick->setformat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>
輸出:
程式2:
// Create a new imagick object
$imagick = new Imagick();
// Set the font - make sure .ttf font file
// is placed in same folder
$imagick->setFont('FFF_Tusj.ttf');
// Write the caption in a image
$imagick->newPseudoImage(800, 350, "caption:GeekforGeeks");
// Show the output
$imagick->setformat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>
輸出: