Title: Adding Text onto image
Last modified: August 21, 2016

---

# Adding Text onto image

 *  [Alanrh](https://wordpress.org/support/users/alanrh/)
 * (@alanrh)
 * [12 years ago](https://wordpress.org/support/topic/adding-text-onto-image/)
 * I am creating a page where I want to display a coupon that my visitors can print.
   I was hoping to use an image as my coupon with a text(code) on top of the image
   that will display the expiration date on the image.
 * I have the code to create a date Xnumbers of days plus from todays date.
 *     ```
       [php]
       $future = mktime(0,0,0,date("m"),date("d")+14,date("Y"));
       $mydate = date("F j, Y", $future);
       echo $mydate;
       [/php]
       ```
   
 * I thought just placing a text area on the image would be a simple solution, however
   I cannot seem to find the way with WordPress.
 * Any and all help is appreciated,
    Alanrh [http://www.liangs-garden.com](http://www.liangs-garden.com)

Viewing 1 replies (of 1 total)

 *  [Peter Lawrenson](https://wordpress.org/support/users/lorro/)
 * (@lorro)
 * [12 years ago](https://wordpress.org/support/topic/adding-text-onto-image/#post-4877332)
 * Hi, Looks like you want to make an image the fly? You need to make the image 
   in memory, save it to disk, and return the required html. You cannot output an
   image you just made directly in the middle of other html.
 * Here are the steps needed:
 *     ```
       // create an image
       $im  =  imagecreate($width, $height);
   
       // make some colours
       $white  =  imagecolorallocate($im, 255, 255, 255);
       $black  =  imagecolorallocate($im, 0, 0, 0);   
   
       // set a background, or use a jpg
       imagefill($im, 0, 0, $white);
   
       // write something, try font number 2
       imagestring($im, $font_number, $x, $y, $text, $black);
   
       // we need somewhere to put the image
       $path = a server path to some temporary directory
       // make a unique number to ensure image is not cached
       $unique = time();
       $url = $path.$unique.'gif';
       // save the image to disk
       $result = imagegif($im, $url);
   
       // get the http address for the image
       $url = 'http://'.DOMAIN.'/ whatever directory you used above '.$unique.'.gif';
       print '<img src="'.$url.'" />';
   
       // release the memory
       imagedestroy($im);
       ```
   
 * I cannot flesh it out for you. If you get stuck, refer to the [PHP image functions](http://www.php.net/manual/en/ref.image.php).

Viewing 1 replies (of 1 total)

The topic ‘Adding Text onto image’ is closed to new replies.

## Tags

 * [image](https://wordpress.org/support/topic-tag/image/)
 * [text field](https://wordpress.org/support/topic-tag/text-field/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Peter Lawrenson](https://wordpress.org/support/users/lorro/)
 * Last activity: [12 years ago](https://wordpress.org/support/topic/adding-text-onto-image/#post-4877332)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
