• For a blog layout i am doing, i want to have the text written in a font that is not a default web font. I found a way to do this using the php GD function. How do i modify it so instead of the text, the script would take the post title, run it through the script and display the title as a graphic. The code i am using is

    <?php
    // Set the content-type
    header("Content-type: image/png");

    // Create the image
    $im = imagecreatetruecolor(400, 30);

    // 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, 399, 29, $white);

    // The text to draw
    $text = 'Post Title Will Go here';
    // Replace path by your own font path
    $font = 'bloody.ttf';

    // Add some shadow to the text
    imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

    // Add the text
    imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

    // Using imagepng() results in clearer text compared with imagejpeg()
    imagepng($im);
    imagedestroy($im);
    ?>

    I am still very new to the core wordpress coding and i would appreciate any help. Thanks -Nick

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘php GD function for titles’ is closed to new replies.