Search code examples
phpimagecolorsemboss

PHP: Deboss the text with font


Please have a look on the following link, you will get the deboss text:

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

I know how to emboss the text:

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

This is the following code to make the text by php and get emboss effect:

 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);

How do U create the Deboss effect?


Solution

  • For Deboss Effect please apply the following line of code:

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

    Thanks