The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


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).

    http://www.php.net/manual/en/ref.image.php

  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..

    Code:
    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    session_start();
    header("Content-type: image/png");
    if ($_SESSION["message"]){
    $message = $_SESSION["message"];
    }else{
    $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);
    
    imagepng($im);
    imagedestroy($im);
    ?>
    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

 Credits

Copyright 1999 - 2012