Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


Results 1 to 4 of 4

Thread: Help with simple php script.

  1. #1

    Help with simple php script.

    I'm pretty much a beginner here. But I've gotten the hang of some things. I just need some pointers. http://www.maximum-voltage.com/Userb...ator/heart.php Something I'm working on for my site. I got it all the way I want it.. but I want to know if it's possible to keep the text completely centered in the image. Depending on how many characters are put in, it moves off to the side. I want to make it completely centered, if it's possible. And is it possible to create a stroke on the text. Or would I have to edit the font file?

  2. #2
    It all depends on how you're generating the image.

    I assume you're using the GD library functions available by default in PHP. There are functions which will tell you the width of a character in a given font. You know how wide that image is (or you can make it wider if you're building it out of pieces by tiling the middle piece). And, you tell it where to start drawing the text. You've got all the info you need to center the text (or to know it's going to be too wide to fit on the image).


  3. #3
    Okay, someone helped me get it centered. But it takes out the font that I want for it. And I can't figure out how to get it back on right. I browsed through that link. And I get some of it. But can anyone help me get the font back in? Here's the script..

    error_reporting(E_ALL ^ E_NOTICE);
    header("Content-type: image/png");
    if ($_SESSION["message"]){
    $message = $_SESSION["message"];
    $message = $_GET['message'];}
    $im = imagecreatefrompng("Heart1.png");
    //$message_width = imagettfbbox(10, 0, "visitor.ttf", $message);
    //$message_start = (350 - ($message_width[2] + 123));
    //$color = imagecolorallocate($im, 0, 0, 0);
    //imagettftext($im, 10, 0, $message_start, 14, $color, "visitor.ttf", $message);
    $text_color = imagecolorallocate($im, 0, 0, 0);
    $imgx     = (imagesx($im) - 7.5 * strlen($message)) / 2;
    $imgy     = (imagesy($im)/5) ;
    imagestring($im, 3, $imgx, $imgy, $message, $text_color);
    Last edited by MaxEvans; February 1st, 2008 at 03:35 PM.

  4. #4
    Can anyone help? All I need is to figure out how to set the font. That's all. Nothing big.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012