narjis Posted May 28, 2011 Share Posted May 28, 2011 I've taken this eg from php manual site for displaying txt on image wonder why it is not working <?php // Create a 300x150 image $im = imagecreatetruecolor(300, 150); $black = imagecolorallocate($im, 0, 0, 0); $white = imagecolorallocate($im, 255, 255, 255); // Set the background to be white imagefilledrectangle($im, 0, 0, 299, 299, $white); // Path to our font file $font = './arial.ttf'; // First we create our bounding box for the first text $bbox = imagettfbbox(10, 45, $font, 'Powered by PHP ' . phpversion()); // This is our cordinates for X and Y $x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 25; $y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5; // Write it imagettftext($im, 10, 45, $x, $y, $black, $font, 'Powered by PHP ' . phpversion()); // Create the next bounding box for the second text $bbox = imagettfbbox(10, 45, $font, 'and Zend Engine ' . zend_version()); // Set the cordinates so its next to the first text $x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) + 10; $y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5; // Write it imagettftext($im, 10, 45, $x, $y, $black, $font, 'and Zend Engine ' . zend_version()); // Output to browser header('Content-Type: image/png'); imagepng($im); imagedestroy($im); ?> Quote Link to comment Share on other sites More sharing options...
harristweed Posted May 28, 2011 Share Posted May 28, 2011 You need the font in the same location as the code! Quote Link to comment Share on other sites More sharing options...
narjis Posted May 28, 2011 Author Share Posted May 28, 2011 they are in the same location. Quote Link to comment Share on other sites More sharing options...
Tonic-_- Posted May 28, 2011 Share Posted May 28, 2011 That coding will work, the issue may be that GD Lib is not installed on the system with freetype. make a test page with <?php phpinfo(); ?> and scroll through it to double check all the PHP modules that are installed on the system and make sure GD is on the list. Quote Link to comment Share on other sites More sharing options...
narjis Posted May 28, 2011 Author Share Posted May 28, 2011 my gd lib is enabled still not working I think working imagettfbox is not working. Quote Link to comment 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.