Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts

    No text outputting in GD

    Hi,

    When I use the following code to generate image with GD:

    PHP Code:
    <?php

    header
    ("Content-type: image/png");
    $image imagecreate(256,50);
    $color imagecolorallocate($image,255,255,0);
    $color2 imagecolorallocate($image,255,0,0);
    imagefill($image,0,0,$color2);
    imagettftext($image,25,0,25,15,$color,"arial","test");
    imagepng($image);
    imagedestroy($image);

    ?>
    It works on my own server, but when I test it at ByetHost it does not work. It only outputs a red image without the text. For some reason the text is not outputted into the image. I asked support from ByetHost but they just keep saying the function imagettftext() works well.

    Any help?
    PHP 5 & MySQL 5 (Y)

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    might just be a difference in versions between what your running and what they're running,

    if they say it works the same, ask them if they can put up a small example on your site.

  • #3
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Your website should have an "admin" folder that you access to check on how your site is running, such as the IP address's of visitors and where they come from, etc. I also have this code in the "admin" folder.

    PHP Code:
    <?php
        phpinfo
    ();
    ?>
    To check on the version of PHP and how it is setup.
    Leonard Whistler

  • #4
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    actually you should be able to run that from anywhere on the site.

  • #5
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Okay. I made it E_ALL, the error reporting I mean.

    Now I have figured out that the script couldn't load font...
    PHP 5 & MySQL 5 (Y)

  • #6
    New Coder
    Join Date
    Jan 2007
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    the ttf font file needs to be included with the script, ie: in the same folder

  • #7
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    it can be in any folder, but requires a system path to the file.

  • #8
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Umm,

    This is the code:
    Code:
    <?php
    error_reporting(E_ALL); ini_set('display_errors', true);
    
    $image = imagecreate(256,50);
    $color = imagecolorallocate($image,255,255,0);
    $color2 = imagecolorallocate($image,255,0,0);
    imagefill($image,0,0,$color2);
    imagettftext($image,25,0,25,15,$color,"tahoma.ttf","test");
    
    if ( !headers_sent() ) {
            header("Content-type: image/png");
            imagepng($image);
    }
    imagedestroy($image);
    ?>
    And I have uploaded tahoma.ttf in the same directory where the script is. Still cannot load/find font?
    PHP 5 & MySQL 5 (Y)

  • #9
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    I just loaded it on my server and it runs fine.
    but I used "ARIAL.ttf"


  •  

    Posting Permissions

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