hey guys, I'm having problem when I'm excuting this code PHP: <?php header ("Content-type: image/jpg"); $img_handle = ImageCreate (230, 20) or die ("Cannot Create image"); $back_color = ImageColorAllocate ($img_handle, 0, 10, 10); $txt_color = ImageColorAllocate ($img_handle, 233, 114, 191); ImageString ($img_handle, 31, 5, 5, "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 ?
You are sending a image/png mime header but sending a PNG image data! Change the header to PHP: header ("Content-type: image/png");
PHP: <?php ob_start(); header ("Content-type: image/png"); $img_handle = ImageCreate (230, 20) or die ("Cannot Create image"); $back_color = ImageColorAllocate ($img_handle, 0, 10, 10); $txt_color = ImageColorAllocate ($img_handle, 233, 114, 191); ImageString ($img_handle, 31, 5, 5, "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); ?>
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 (230, 20) or die ("Cannot Create image"); $back_color = ImageColorAllocate ($image, 1, 10, 10); $text_color = ImageColorAllocate ($image, 233, 114, 191); ImageString ($image, 31, 5, 5, "My first Program with GD", $text_color); ImagePng ($image); ?> page.php <html> <head></head> <body> <img src="image.php"/> </body> </html>
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 ?
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