久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 PHP 中使用 Imagick 換行文本,以便將其繪制

How can I wrap text using Imagick in PHP so that it is drawn as multiline text?(如何在 PHP 中使用 Imagick 換行文本,以便將其繪制為多行文本?)
本文介紹了如何在 PHP 中使用 Imagick 換行文本,以便將其繪制為多行文本?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

PHP 中的 Imagick 庫允許您在圖像上繪制文本.

The Imagick library in PHP allows you to draw text on top of an image.

我怎樣才能告訴 Imagick 根據(jù)一些有界文本框來換行文本,以便單詞顯示為多行文本而不是單行?

How can I tell Imagick to wrap the text based upon some bounded text box, so that the words appear as multiline text rather than a single line?

推薦答案

用法:

list($lines, $lineHeight) = wordWrapAnnotation($image, $draw, $msg, 140);
for($i = 0; $i < count($lines); $i++)
    $image->annotateImage($draw, $xpos, $ypos + $i*$lineHeight, 0, $lines[$i]);

功能:

/* Implement word wrapping... Ughhh... why is this NOT done for me!!!
    OK... I know the algorithm sucks at efficiency, but it's for short messages, okay?

    Make sure to set the font on the ImagickDraw Object first!
    @param image the Imagick Image Object
    @param draw the ImagickDraw Object
    @param text the text you want to wrap
    @param maxWidth the maximum width in pixels for your wrapped "virtual" text box
    @return an array of lines and line heights
*/
function wordWrapAnnotation(&$image, &$draw, $text, $maxWidth)
{
    $words = explode(" ", $text);
    $lines = array();
    $i = 0;
    $lineHeight = 0;
    while($i < count($words) )
    {
        $currentLine = $words[$i];
        if($i+1 >= count($words))
        {
            $lines[] = $currentLine;
            break;
        }
        //Check to see if we can add another word to this line
        $metrics = $image->queryFontMetrics($draw, $currentLine . ' ' . $words[$i+1]);
        while($metrics['textWidth'] <= $maxWidth)
        {
            //If so, do it and keep doing it!
            $currentLine .= ' ' . $words[++$i];
            if($i+1 >= count($words))
                break;
            $metrics = $image->queryFontMetrics($draw, $currentLine . ' ' . $words[$i+1]);
        }
        //We can't add the next word to this line, so loop to the next line
        $lines[] = $currentLine;
        $i++;
        //Finally, update line height
        if($metrics['textHeight'] > $lineHeight)
            $lineHeight = $metrics['textHeight'];
    }
    return array($lines, $lineHeight);
}

這篇關于如何在 PHP 中使用 Imagick 換行文本,以便將其繪制為多行文本?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產(chǎn)品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產(chǎn)品的總訂單數(shù))
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產(chǎn)品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產(chǎn)品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 免费不卡一区 | 国产精品一区二区三区在线 | 国产免费视频 | 久久国产精品精品国产色婷婷 | 久久久一二三区 | 一区二区三区视频在线观看 | 天天玩天天干天天操 | 91精品国产综合久久久久久丝袜 | 国产免费一区二区 | 国产精品不卡视频 | 欧美日韩一区二区在线观看 | 亚洲综合大片69999 | 一区二区三区四区av | 免费观看一级视频 | 91精品国产91久久久久久吃药 | 日韩久久中文字幕 | 亚洲xxxxx | 久久久999免费视频 999久久久久久久久6666 | 天天久 | 亚洲3级 | 日韩伦理一区二区 | 国产一区二区在线免费观看 | 视频精品一区 | 亚洲一区不卡 | 激情 亚洲 | 久久久久久91香蕉国产 | 久久成人国产 | 久久成人一区二区三区 | 欧美aⅴ | 一二区视频 | 国产精品国产三级国产aⅴ中文 | 情侣黄网站免费看 | 密室大逃脱第六季大神版在线观看 | 久久久www成人免费无遮挡大片 | 亚洲天天| 精品久久久久久久久久久 | 国产高清91| 色吧久久| 国产福利观看 | 日韩欧美一区二区三区免费观看 | 日韩精品久久一区二区三区 |