Problem with image handling

Discussion in 'PHP' started by SaeedGh, Aug 13, 2009.

  1. #1
    Hi,

    When i run this simple script in my new VPS, the background of image is black. in other hosts the background is white. what is my mistake in php configurations?


    <?php
    
    header ('Content-type: image/png');
    
    $im = @imagecreatetruecolor(120, 20)or die('Cannot Initialize new GD image stream');
    
    $bg_color = imagecolorallocate($im, 255, 255, 255);
    imagefill($im, 0, 0, $bg_color);
    
    $text_color = imagecolorallocate($im, 233, 14, 91);
    imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);
    imagepng($im);
    imagedestroy($im);
    
    ?>
    PHP:

    PHP: 5.2
    GD: 2.2 (all features is enable)

    (image is attached)

    Thank you very much.
     

    Attached Files:

    SaeedGh, Aug 13, 2009 IP
  2. Pudge1

    Pudge1 Well-Known Member

    Messages:
    912
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    Digital Goods:
    1
    #2
    Gah I just had this problem like a week ago but I don't remember what I did to fix it. I'll tell you if I remember.
     
    Pudge1, Aug 13, 2009 IP
  3. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Probably need to clear your cache, it probably still has an old version you did in the browser cache on the old host cuz that code clearly allocates white.
     
    kblessinggr, Aug 13, 2009 IP
  4. stOK

    stOK Active Member

    Messages:
    114
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #4
    Compare what the following returns
    <?php
    var_dump(gd_info());
    ?>
    And check imagecolorallocate and imagefill return values.
     
    stOK, Aug 13, 2009 IP
  5. SaeedGh

    SaeedGh Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Please remember! :(

    I cleared cache and even used of another web browser. then change the script's name and...


    This is result of var_dump(gd_info()):

    array(12) {
      ["GD Version"]=>
      string(27) "bundled (2.0.34 compatible)"
      ["FreeType Support"]=>
      bool(true)
      ["FreeType Linkage"]=>
      string(13) "with freetype"
      ["T1Lib Support"]=>
      bool(true)
      ["GIF Read Support"]=>
      bool(true)
      ["GIF Create Support"]=>
      bool(true)
      ["JPG Support"]=>
      bool(true)
      ["PNG Support"]=>
      bool(true)
      ["WBMP Support"]=>
      bool(true)
      ["XPM Support"]=>
      bool(true)
      ["XBM Support"]=>
      bool(true)
      ["JIS-mapped Japanese Font Support"]=>
      bool(false)
    }
    Code (markup):
    imagecolorallocate return: 16777215
    imagefill return: 1

    I test a simpler code:

    <?php
    
    $im = @imagecreatetruecolor(120, 20)or die('Cannot Initialize new GD image stream');
    
    $bg_color = imagecolorallocate($im, 255, 255, 255);
    imagefill($im, 0, 0, $bg_color);
    
    header ('Content-type: image/png');
    imagepng($im);
    imagedestroy($im);
    
    ?>
    PHP:
    Just is BLACK! even if change RBGs.
    I believe that my new VPS is not configured correctly/completely. i installed last version of GD but it seems that it is not enough!
    :(
     
    SaeedGh, Aug 13, 2009 IP