PHP Image Problem

Discussion in 'PHP' started by Pudge1, Aug 31, 2009.

  1. #1
    
    header('Content-Type: image/png');
    
    $img = @imagecreatefrompng('christmas.png');
    $font = imageloadfont('font.ttf');
    $fontcolor = imagecolorallocate($img,255,255,255);
    imagestring($img,$font,30,5,$countdown,$fontcolor);
    imagepng($img);
    imagedestroy($img);
    
    Code (markup):
    It returns an image that "Cannot be Displayed"
     
    Pudge1, Aug 31, 2009 IP
  2. codebreaker

    codebreaker Well-Known Member

    Messages:
    281
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #2
    You have to set the header after the php code
    this should work :

    
    
    
    $img = @imagecreatefrompng('christmas.png');
    $font = imageloadfont('font.ttf');
    $fontcolor = imagecolorallocate($img,255,255,255);
    imagestring($img,$font,30,5,$countdown,$fontcolor);
    header('Content-Type: image/png');
    imagepng($img);
    imagedestroy($img);
    
    Code (markup):
     
    codebreaker, Aug 31, 2009 IP
  3. Pudge1

    Pudge1 Well-Known Member

    Messages:
    912
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    Digital Goods:
    1
    #3
    I tried that. Still doesn't work.
     
    Pudge1, Aug 31, 2009 IP
  4. HivelocityDD

    HivelocityDD Peon

    Messages:
    179
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    which browser you are using ? If you are using IE it wont display the png files. Try in firefox and if it is getting displayed ...
     
    HivelocityDD, Sep 1, 2009 IP
  5. Pudge1

    Pudge1 Well-Known Member

    Messages:
    912
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    Digital Goods:
    1
    #5
    I am using FF.
     
    Pudge1, Sep 1, 2009 IP
  6. Dollar

    Dollar Active Member

    Messages:
    2,598
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    90
    #6
    Try echo $img
     
    Dollar, Sep 2, 2009 IP
  7. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #7
    Make PHP tell you about everything on the first line "error_reporting(E_ALL);"
    Comment out the header() line
    Remove the error supression symbol (@)
    Look directly at the URL in your browser

    A lot of times what is happening is there is an error in one of the functions and the resulting image is currupted by the error messages.
     
    joebert, Sep 2, 2009 IP