Graphing with PHP using GD - error !

Discussion in 'PHP' started by coool, Jul 12, 2007.

  1. coool

    coool New Member

    Joined:
    Jul 12, 2007
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    0
    hey guys,

    I'm having problem when I'm excuting this code

    PHP:
    <?php
            header 
    ("Content-type: image/jpg");
            
    $img_handle ImageCreate (23020) or die ("Cannot Create image");
            
    $back_color ImageColorAllocate ($img_handle01010);
            
    $txt_color ImageColorAllocate ($img_handle233114191);
            
    ImageString ($img_handle3155,  "My first Program with GD"$txt_color);
            
    ImagePng ($img_handle);
    ?>
    This is the output:

    Code:
    ‰PNG  IHDRæ£þÓêPLTE ér¿`ŽLÚIDAT(‘åбAàŸMhF®!ža’+(„WÙË&ª;‘xë”Z…‡Ði'J*D£RÑ+®0wÁ¯`«ÙýòÏfø³Sc CYeŸGEý˜õà«*T,(´ªšðñ£Peí|&H»;?&¦±éÖ³½54IÇ%¥öÉé¿×‘[¢•!‘i¡)1kg$;ÇP E‚˜o™¶²,{»—z÷·†…Âå:`Ž¾´¹Ì”¨Ž,³fSñƒ8Ÿ¨Æ7ȽíEµ¯E´ª,ÒNçÛ@µ4&‚øg••Gé2ü¶'€£D?Ñ<_FIEND®B`‚ 
    
    what's wrong with my code !

    do you have any clue ?
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    You are sending a image/png mime header but sending a PNG image data!
    Change the header to

    PHP:
    header ("Content-type: image/png"); 
     
  3. coool

    coool New Member

    Joined:
    Jul 12, 2007
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    0
    I've changed the header..

    same problem.. :(
     
  4. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    PHP:
     <?php
             ob_start
    ();
             
    header ("Content-type: image/png");
             
    $img_handle ImageCreate (23020) or die ("Cannot Create image");
             
    $back_color ImageColorAllocate ($img_handle01010);
             
    $txt_color ImageColorAllocate ($img_handle233114191);
             
    ImageString ($img_handle3155,  "My first Program with GD"$txt_color);
             
    ob_clean(); // clean the output buffer before sending the image data, nothing more than the image data should be sent
             
    ImagePng ($img_handle);
     
    ?> 
     
     
  5. coool

    coool New Member

    Joined:
    Jul 12, 2007
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    0
    hmmm

    I've tried your code.. It doesn't work !

    but no worries, cuz the problem is already solved now :)

    I just had to saparate the code..

    image.php
    PHP:
    <?php
            header 
    ("Content-type: image/jpg");
            
    $image ImageCreate (23020) or die ("Cannot Create image");
            
    $back_color ImageColorAllocate ($image11010);
            
    $text_color ImageColorAllocate ($image233114191);
            
    ImageString ($image3155,  "My first Program with GD"$text_color);
            
    ImagePng ($image);
    ?>
    page.php
    <html>
    <head></head>
    <body>

    <img src="image.php"/>

    </body>
    </html>
     
  6. coool

    coool New Member

    Joined:
    Jul 12, 2007
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    0
    okay ! .. now how can have a graph ! with x-axis and y-axis taken from one table in MySQL query !

    for example:

    FruitsTable
    fruitName numberAvailable
    Apple 2
    Orange 8
    Banana 5

    I want the x-axis to be my fruitName
    and the y-axis to be the numberAvailable of the fruit

    Query = "SELECT fruitName, numberAvailable FROM FruitsTable"

    then ?
     
  7. coool

    coool New Member

    Joined:
    Jul 12, 2007
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    0
    any help ! ..

    just give a simple example where I have a graph that has x-axis and y-axis taken form a mySQL query from only one table between two columns

    one column --> count(column1)
    second column --> actual value of itself
     
  8. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice