PHP Conference Japan 2024

ImagickDraw::setFontSize

(PECL imagick 2, PECL imagick 3)

ImagickDraw::setFontSize設定使用文字註釋時的字型大小

說明

public ImagickDraw::setFontSize(float $pointsize): bool
警告

此函式目前沒有說明文件;僅提供其參數列表。

設定使用文字註釋時的字型大小。

參數

pointsize

點大小

回傳值

無回傳值。

範例

範例 #1 ImagickDraw::setFontSize() 範例

<?php
function setFontSize($fillColor, $strokeColor, $backgroundColor) {

$draw = new \ImagickDraw();

$draw->setStrokeOpacity(1);
$draw->setStrokeColor($strokeColor);
$draw->setFillColor($fillColor);
$draw->setStrokeWidth(2);
$draw->setFont("../fonts/Arial.ttf");

$sizes = [24, 36, 48, 60, 72];

foreach (
$sizes as $size) {
$draw->setFontSize($size);
$draw->annotation(50, ($size * $size / 16), "Lorem Ipsum!");
}

$imagick = new \Imagick();
$imagick->newImage(500, 500, $backgroundColor);
$imagick->setImageFormat("png");
$imagick->drawImage($draw);

header("Content-Type: image/png");
echo
$imagick->getImageBlob();
}

?>

新增筆記

使用者貢獻的筆記 2 則筆記

hmkrox at gmail dot com
15 年前
參數中使用的字體大小不是以點為單位的大小(1 點 = 1/72 英吋),而是字體高度的像素值。
因此,如果您要修改預定列印的文件,則應進行轉換以獲得正確的字體大小。
例如,如果您的文件解析度為 300ppi,您應該將字體大小乘以 25/6 才能獲得正確的字體行為。
jgsujith at in dot com
15 年前
<?php
$sourceFile
='in.jpg';
$textWrite='God is Great';
$x=50;
$y=50;
$fontColor='#000000';
$fontSize=34;

$colorPix=new ImagickPixel ($fontColor);
$image=new Imagick ($sourceFile);
$draw=new ImagickDraw();

$draw->setFontSize($fontSize);//設定使用文字註釋時的字體大小

$draw->setFillColor($colorPix);//設定繪製填充物件時要使用的填充顏色

$image->annotateImage($draw,$x,$y,0,$textWrite);//使用文字為影像加上註釋

$image->writeImage('out.jpg');//將影像寫入指定的檔案名稱
?>
To Top