函式:ImagickDraw::getTextKerning()
適用版本:ImageMagick 6.3.1 及以上版本
用法:ImagickDraw::getTextKerning() 方法用於獲取當前 ImagickDraw 物件中設定的文字字距(字元之間的間距)。
語法:public float ImagickDraw::getTextKerning ( void )
引數:無
返回值:返回一個浮點數,表示當前設定的文字字距。
示例:
// 建立一個 Imagick 物件
$image = new Imagick();
// 建立一個 ImagickDraw 物件
$draw = new ImagickDraw();
// 設定文字字型和字型大小
$draw->setFont('Arial');
$draw->setFontSize(20);
// 設定文字字距為2
$draw->setTextKerning(2);
// 在影象上繪製文字
$draw->annotation(50, 50, 'Hello, World!');
// 將繪製好的影象應用到 Imagick 物件
$image->drawImage($draw);
// 顯示影象
header('Content-type: image/png');
echo $image;
在上面的示例中,我們建立了一個 Imagick 物件和一個 ImagickDraw 物件。然後,我們設定了文字字型和字型大小,並使用 setTextKerning() 方法將文字字距設定為2。最後,我們在影象上使用 annotation() 方法繪製了一個文字,並將繪製好的影象應用到 Imagick 物件上,最終將影象以 PNG 格式輸出。
請注意,為了執行上述示例,您需要安裝 ImageMagick 擴充套件,並確保在 PHP 中啟用了 Imagick 擴充套件。