tobeyt23 Posted March 6, 2006 Share Posted March 6, 2006 Can someone explain how imageftbbox works? Also how can you center text with a text block. Another question i have can you auto resize an image? I tried and it just seemed to crop it instead of resize. Any info would be great. Quote Link to comment https://forums.phpfreaks.com/topic/4265-solved-gd-help/ Share on other sites More sharing options...
tobeyt23 Posted March 8, 2006 Author Share Posted March 8, 2006 Still working on centering text and ideas? Quote Link to comment https://forums.phpfreaks.com/topic/4265-solved-gd-help/#findComment-15485 Share on other sites More sharing options...
tobeyt23 Posted March 8, 2006 Author Share Posted March 8, 2006 Is see on php.net for image that this will place the text centered on the image:[code]$px = (imagesx($im) - 7.5 * strlen($string)) / 2;[/code]However i need to center it on a certain area in the image not the image iself. When doing a pdf you can set the XY for the boundingbox not sure if this can be done in GD as that would do the trick. Any suggestions????? Quote Link to comment https://forums.phpfreaks.com/topic/4265-solved-gd-help/#findComment-15509 Share on other sites More sharing options...
Barand Posted March 8, 2006 Share Posted March 8, 2006 If you want to centre in a certain area then if X is the centre point of the area, the start of the text string ($px) will be at (X - textwidth/2)This will taka text string, split it into lines of approx 25 charcters, and centre the lines of text in the image[code]<?php$font = "C:/windows/fonts/arial.ttf";$text = $_GET['text'];$im = imagecreate (200, 80);$black = imagecolorallocate($im, 0x00, 0x00, 0x00);$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);$text_array = explode ("\n", wordwrap($text, 25));$image_width = imagesx($im);$y = 5;foreach ($text_array as $line) { $box = imagettfbbox(12,0,$font,$line); $text_width = $box[2] - $box[0]; // calc pos to centre the text $x = ($image_width - $text_width) / 2; $y += 20; imagettftext($im, 12, 0, $x, $y, $white, $font, $line);}header("content-type: image/png");imagepng($im);imagedestroy($im);?>[/code]Save it as "centreText.php" and place image on page with<IMG src='centreText.php?text='Now+is+the+time+for+all+good+men+to+come+to+the+aid+of+the+party'> Quote Link to comment https://forums.phpfreaks.com/topic/4265-solved-gd-help/#findComment-15584 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.