• 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
    https://www.liangs-garden.com

Viewing 1 replies (of 1 total)
  • 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 = 'https://'.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.

Viewing 1 replies (of 1 total)
  • The topic ‘Adding Text onto image’ is closed to new replies.