dooper3 Posted February 4, 2007 Share Posted February 4, 2007 I have written code to create an image on the fly to conduct a Turing (sp?!) test, the problem is, I can't seem to center the text in the image properly no matter what I try! Below is the code for my image centering calculations: //Set the positioning for the text $fromleft = (($img['width'] / 2) - ((imagefontwidth($img['font']) * $img['string_length']) / 2)); $fromtop = (($img['height'] / 2) + (imagefontheight($img['font']))); //Create the text itself imagettftext($img['handle'],$img['font_size'],$img['random_angle'],$fromleft,$fromtop,$color,$img['font'],$img['random_string']); No matter what I do it always ends up further to the right than in the center. Thanks! Link to comment https://forums.phpfreaks.com/topic/37038-centering-text-in-a-gd-generated-security-image/ Share on other sites More sharing options...
dooper3 Posted February 4, 2007 Author Share Posted February 4, 2007 Solved it myself! wasn't taking into account the font size, the x-positioning line now reads: $fromleft = (($img['width'] / 2) - (imagefontwidth($img['font']) * $img['string_length'] * ($img['font_size'] / 12))); If anyone else out there wanted to know... Link to comment https://forums.phpfreaks.com/topic/37038-centering-text-in-a-gd-generated-security-image/#findComment-176860 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.