JustinK101 Posted June 15, 2007 Share Posted June 15, 2007 Hello, I am trying to use the GD Library to draw an image with text in it. Here is the code I am using: $img_handle = ImageCreate (230, 20) or die ("Fatal Error: Cannot create image in PHP library GD."); $back_color = ImageColorAllocate ($img_handle, 0, 10, 10); $txt_color = ImageColorAllocate ($img_handle, 233, 114, 191); ImageString ($img_handle, 31, 5, 5, $row_customer['approx_number_of_units'], $txt_color); This is simply outputting: ‰PNG IHDRæ£þÓêPLTE ér¿`ŽL+IDATxœc`ià@IÆðÈ2œÏäÃ<#‹ßUø}ô!Ÿ^ò%õ ÆƳÚýIEND®B`‚ Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/55786-gd-image-lib-not-working/ Share on other sites More sharing options...
JustinK101 Posted June 15, 2007 Author Share Posted June 15, 2007 Ok the trick to place GD images in your page with other html and php content is to put the GD php code in a seperate file. For example: FileName: gd_create_text_image.php <?php header("Content-type: image/png"); $string = $_GET['text']; $img_handle = ImageCreate(100, 20) or die ("Fatal Error: Cannot create image in PHP library GD."); $back_color = ImageColorAllocate ($img_handle, 255, 255, 255); $txt_color = ImageColorAllocate ($img_handle, 0, 0, 0); ImageString($img_handle, 5, 5, 5, $string, $txt_color); imagepng($img_handle); imagedestroy($img_handle); ?> Then in your page simply use a standard HTML img tag as follow: echo '<img src="gd_create_text_image.php?text=' . $row['approx_number_of_units'] . '">'; Quote Link to comment https://forums.phpfreaks.com/topic/55786-gd-image-lib-not-working/#findComment-275594 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.