close

 


說明

array imagepsbbox ( string $text , resource $font , int $size )
array imagepsbbox ( string $text , resource $font , int $size , int $space , int $tightness , float $angle )
給出一個使用 PostScript Type1 字體的文本方框。

圍繞文本範圍的虛擬方框是用從字符度量學中的可用信息來計算的,
不幸的是往往和實際上光柵生成的文本的結果有少許不同。如果角度為 0 度,
(根據經驗)文本在每個方向上都需要多 1 個像素。

<?php
// 創建圖像的句柄
$im = imagecreatetruecolor(200, 200);

// 分配顏色
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);

// 載入 PostScript 字體
$font = imagepsloadfont('font.pfm');

// 設置文本方框
$bbox = imagepsbbox('Sample text is simple', $font, 12);

// 定義 X 和 Y
$x = ($bbox[2] / 2) - 10;
$y = ($bbox[3] / 2) - 10;

// 字體寫入圖像
imagepstext($im, 'Sample text is simple', $font, 12, $black, $white, $x, $y);

// 輸出並釋放內存
header('Content-type: image/png');

imagepng($im);
imagedestroy($im);
?>

arrow
arrow
    全站熱搜

    stockwfj3 發表在 痞客邦 留言(0) 人氣()