亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Image-Workshop:圖像中的中心文本

Image-Workshop:圖像中的中心文本

PHP
慕姐8265434 2022-07-09 09:55:13
我正在使用PHP 7.1.33和"sybio/image-workshop": "^2.1"- PHPImageWorkshop - 創建/修改圖像。我目前正在生成如下圖像:<?phprequire_once 'vendor/autoload.php';use PHPImageWorkshop\ImageWorkshop;$layer = ImageWorkshop::initFromPath(__DIR__.'\images\bank.jpg');$layer->applyFilter(IMG_FILTER_CONTRAST, 40, null, null, null, true); // constrast$layer->applyFilter(IMG_FILTER_BRIGHTNESS, 10, null, null, null, true); // brightness// apply text$text = "This is a test text";$date = date("Y-m-d");$font = 5; // Internal font number (http://php.net/manual/en/function.imagestring.php)$color = "ffffff";$positionX = 0;$positionY = 0;$align = "horizontal";$layer->writeText($text, $font, $color, $positionX, $positionY, $align);// Saving / showing...$layer->save(__DIR__.'/output/', 'bank.jpg', true, null, 95);我得到以下輸出:但是,我想得到:有什么建議如何指定字體并將文本以中間大字體居中?感謝您的回復!
查看完整描述

2 回答

?
qq_笑_17

TA貢獻1818條經驗 獲得超7個贊

您需要先獲取圖層尺寸,然后將其除以 2


$width = $layer->getWidth(); // in pixel

$height = $layer->getHeight(); // 


$positionX = int($width / 2) ;

$positionY = int($height / 2) ;


$layer->writeText($text, $font, $color, $positionX, $positionY, $align);


查看完整回答
反對 回復 2022-07-09
?
烙印99

TA貢獻1829條經驗 獲得超13個贊

創建一個新的文本圖層,然后將其放在現有圖層的頂部。關鍵是'MM'進行居中的參數。


$font = '/path/to/font.ttf';

$size = 100;

$color = "ffffff";

$align = "horizontal";


$textLayer = ImageWorkshop::initTextLayer($text, $font, $size, $color, 0, 0);

$layer->addLayer(1, $textLayer, 0, 0, 'MM');

$size此外,您可以使用變量設置字體大小。


查看完整回答
反對 回復 2022-07-09
  • 2 回答
  • 0 關注
  • 163 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號