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. 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'] . '">'; 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
Archived
This topic is now archived and is closed to further replies.