the-botman Posted December 2, 2009 Share Posted December 2, 2009 Hi ... see i need the text of the name and number to start in the center and always be in the center now with the code i have the text starts in the center and goes on to the rite it does not stay in the center any ideas guys? here is my code $white = ImageColorAllocate($im, 255, 255, 255); $start_xx = 80; $start_yy = 50; $start_x = 70; $start_y = 90; Imagettftext($im, 15, 0, $start_xx, $start_yy, $white, 'image1.ttf', $_GET['name']); Imagettftext($im, 35, 0, $start_x, $start_y, $white, 'arial.ttf', $_GET['number']); Thanks in Advance Botman Link to comment https://forums.phpfreaks.com/topic/183771-help-with-image-text/ Share on other sites More sharing options...
Alex Posted December 2, 2009 Share Posted December 2, 2009 You're going to need to do a little of math to make the text be centered no matter what the string is. To calculate the starting point of the text we need to do: The width of the entire image / 2 - string width / 2. To find the string width of a ttf font we can use imagettfbbox. Example: $bounds = imagettfbbox(35, 0, 'arial.ttf', $_GET['number']); $start_x = IMAGE_WIDTH / 2 - ($bounds[2] - $bounds[0]) / 2; // $bounds[2] - $bounds[0] will be the width of the string, check the documentation for more info. Untested, but should work. Make sure to replace IMAGE_WIDTH with the width of the image ($im) that you're dealing with. imagettfbbox Link to comment https://forums.phpfreaks.com/topic/183771-help-with-image-text/#findComment-969996 Share on other sites More sharing options...
the-botman Posted December 2, 2009 Author Share Posted December 2, 2009 see this is how i do it rite now <?php $number = $_GET['number']; $name = $_GET['name']; header("Content-Type: image/png"); $im = imagecreatefrompng("soccer-kit.png"); if(!$im){ die("IMAGE CREATION FAILED"); } $white = ImageColorAllocate($im, 255, 255, 255); $start_xx = 80; $start_yy = 50; $start_x = 70; $start_y = 90; Imagettftext($im, 15, 0, $start_xx, $start_yy, $white, 'image1.ttf', $_GET['name']); Imagettftext($im, 35, 0, $start_x, $start_y, $white, 'arial.ttf', $_GET['number']); //Creates the png image and sends it to the browser //100 is the png quality percentage imagepng($im, NULL, 9); ImageDestroy($im); ?> and this is how i show the image echo "<img src=\"image_generator.php?name={$_POST['name']}&number={$_POST['number']}\" />"; how do i make it stay in the center and add a download link i kinda understand what u are saying but i dont know how to add it to this please can you maybe show me thanks alot Botman Link to comment https://forums.phpfreaks.com/topic/183771-help-with-image-text/#findComment-970006 Share on other sites More sharing options...
the-botman Posted December 2, 2009 Author Share Posted December 2, 2009 maybe i might need to save the image for about 5 min then it can auto del or something so i can make the download link and display the image from the saved file not how it is now, but how do i do this? Link to comment https://forums.phpfreaks.com/topic/183771-help-with-image-text/#findComment-970024 Share on other sites More sharing options...
the-botman Posted December 3, 2009 Author Share Posted December 3, 2009 ok see i have the download link now but i need the text to stay in the center and i need to save the image for 5 min as the-name-they-use.png please can someone show me how to get the text in the center Link to comment https://forums.phpfreaks.com/topic/183771-help-with-image-text/#findComment-970287 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.