Title: php GD function for titles
Last modified: August 18, 2016

---

# php GD function for titles

 *  [hdshngout](https://wordpress.org/support/users/hdshngout/)
 * (@hdshngout)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/php-gd-function-for-titles/)
 * 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)

 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/php-gd-function-for-titles/#post-351340)
 * If this script is embedded in [The Loop](http://codex.wordpress.org/The_Loop),
   then you could try assigning $text as so:
 * $text = $post->post_title;
 * In any case, there is a plugin alternative for this:
 * [http://www.coldforged.org/image-headlines-plugin-for-wordpress-15/](http://www.coldforged.org/image-headlines-plugin-for-wordpress-15/)
 *  Thread Starter [hdshngout](https://wordpress.org/support/users/hdshngout/)
 * (@hdshngout)
 * [20 years, 2 months ago](https://wordpress.org/support/topic/php-gd-function-for-titles/#post-351510)
 * thanks! I was wondering if there was a plugin already made!

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

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

 * 2 replies
 * 2 participants
 * Last reply from: [hdshngout](https://wordpress.org/support/users/hdshngout/)
 * Last activity: [20 years, 2 months ago](https://wordpress.org/support/topic/php-gd-function-for-titles/#post-351510)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
