A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [php] Text in Images

  1. #1
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393

    [php] Text in Images

    Hi,

    I've created a small script which creates an image with some text on. I can change a few things on this image, but not the font of the text in it, or the font size. Now, just to clarify, I want the font to be one loaded in from a .ttf file in the directory that my php file is in; I'm using arial.ttf as a test.

    Here's my code so far:
    Code:
    <?php
    
    // Recieve vars and up them into variables
    $t = $_GET['text']; // Text string
    $h = $_GET['height']; // Height of background
    $w = $_GET['width']; // Width of background
    $x = $_GET['x']; // X position of text
    $y = $_GET['y']; // Y position of text
    
    // Create an image at the size defined in the vars
    $im = @imagecreate($w, $h);
    
    // Set background colour to green
    $bc = imagecolorallocate($im, 0, 255, 0);
    
    // Set text colour to red
    $tc = imagecolorallocate($im, 255, 0, 0);
    
    // Write the text string into an image
    // (resource image, font, x, y, string, text colour)
    imagestring($im, 5, $x, $y,  $t, $tc);
    
    // Output Image
    header("Content-type: image/png");
    imagepng($im);
    
    imagedestroy($im);
    
    ?>
    You can see the results of this here

    Thanks for any help.
    ninjakannon

    - My Website -

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    go to www.php.net and read about imageloadfont and imagepsloadfont

    Musicman

  3. #3
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    OK, thanks for that.

    I didn't use either of those in the end, instead I found "imagettftext" which someone had referenced in the comments on imageloadfont (I think it was that one).

    It now works great with a whole 2 fonts that I've uploaded.
    ninjakannon

    - My Website -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center