簡體   English   中英

PHP:用字體壓制文本

[英]PHP: Deboss the text with font

請查看以下鏈接,您將獲得凸凹文字:

http://www.wristbandtoday.com/wristband/gd/load.php? 路線 = font&size = 30&name = 1391601784Artbrush.ttf&effect = debossed&color = 222222&text = Debossed

我知道如何壓印文字:

$emboss = array(array(2, 0, 0), array(0, -1, 0), array(0, 0, -1));
imageconvolution($im, $emboss, 3, 235);

這是下面的代碼,通過php制作文本並獲得浮雕效果:

 header('Content-Type: image/png');

        // The text to draw
        $text = "Ebossed";
        // Replace path by your own font path
        $font = WWW_ROOT.DS.'fonts/uploads/9559122015-03-27Artbrush.ttf';

        $fontSize = 32;

        $text_angle = 0;

        $text_padding = 0;

        $the_box = $this->_calculateTextBox($text, $font, $fontSize, $text_angle);

        $imgWidth = $the_box["width"] + $text_padding;
        $imgHeight = $the_box["height"] + $text_padding; 

        $im = imagecreatetruecolor($imgWidth, $imgHeight);

        // Create some colors
        $white = imagecolorallocate($im, 255, 255, 255);
        $grey = imagecolorallocate($im, 128, 128, 128);
        $black = imagecolorallocate($im, 0, 0, 0);
        imagefilledrectangle($im, 0, 0, $imgWidth-1, $imgHeight-1, $white);

        // Add some shadow to the text
        imagettftext($im, $fontSize, $text_angle, 0, 32, $grey, $font, $text);

        // Add the text
        imagettftext($im, $fontSize, $text_angle, 0, 32, $black, $font, $text);

        $emboss = array(array(2, 0, 0), array(0, -1, 0), array(0, 0, -1));
        imageconvolution($im, $emboss, 3, 235);

        imagepng($im,WWW_ROOT.DS.IMAGES_URL.'test/newtes.png'); // image path
        imagedestroy($im);

您如何創建Deboss效果?

對於Deboss Effect,請應用以下代碼行:

$debosseffect = array
    (
        array(0, 0, 1),
        array(0, -1, 1),
        array(0, 0, -1)
    );

謝謝

最后我得到了消除浮雕效果的解決方案

$image = imagecreatefromjpeg(WWW_ROOT.DS.IMAGES_URL.'cliparts/'.$img);
        $sharpenMatrix = array
        (
            array(0, 0, 1),
            array(0, -1, 1),
            array(0, 0, -1)
        );

        // calculate the sharpen divisor
        $divisor = 3;

        $offset = 235;

        // apply the matrix
        imageconvolution($image, $sharpenMatrix, $divisor, $offset); 

        header('Content-Type: image/png');
        imagepng($image, null, 9);
        imagegd($image);
        imagedestroy($image);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM