久久久久久久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 根據一些有界文本框來換行文本,以便單詞顯示為多行文本而不是單行?

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模板網!

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

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
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 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 成人久久久 | 精品乱码一区二区三四区 | 亚洲精品一区在线观看 | 欧美一区二区视频 | 波多野吉衣久久 | 99爱在线免费观看 | 中文字幕一区二区三区乱码在线 | 国产欧美日韩综合精品一 | 精品免费视频一区二区 | 国产激情视频在线 | 一区二区三区在线播放视频 | 麻豆精品国产91久久久久久 | 91精品久久久久久久久 | 久久久久久久久99 | 亚洲日本免费 | 久久精品中文字幕 | 亚洲精品在线免费看 | 成人国产网站 | 亚洲欧美一区在线 | 日韩av啪啪网站大全免费观看 | 国产亚洲网站 | 国产一区二区视频免费在线观看 | 国产在线中文 | 久久伊人免费视频 | 欧美一区不卡 | 日本成人在线免费视频 | 国产精品一区二区三区四区五区 | 日本精品久久 | 久久欧美高清二区三区 | 韩日精品在线观看 | 亚洲视频在线观看一区二区三区 | 久久久精品综合 | 亚洲综合一区二区三区 | 精品一区二区三区91 | 国产精品1区2区3区 欧美 中文字幕 | 亚洲精品中文字幕在线观看 | 99亚洲精品| 91亚洲免费 | 日韩精品一区二区三区在线观看 | 亚洲91精品 | 日日摸日日添日日躁av |