SharkBait Posted November 17, 2006 Share Posted November 17, 2006 Hi, I am trying to center text on an image I am creating with the GD.I am currently using [code=php:0]imagestring()[/code] but with that I am not specifing a font like I would with imagettftext()So if I could do something like this:[code]<?php$fontWidth = imagefontwidth($font);$stringLength = strlen("My String") * $fontWidth;?>[/code]But because I am using [code=php:0]imagestring()[/code] I am unsure as how to figure out the default font's width because I dont set a font.Should I use a font and just use imagettftext instead of imagestring? Quote Link to comment Share on other sites More sharing options...
Barand Posted November 17, 2006 Share Posted November 17, 2006 With imagestring() the 2nd arg is the font number to use. Use that same font number in in imagefontwidth() Quote Link to comment Share on other sites More sharing options...
SharkBait Posted November 17, 2006 Author Share Posted November 17, 2006 Ok my centering isnt working.My image is 50 in width.This is what I have:[code]<?php$imgWidth = 50;$text = "HELP";$fontWidth = 5;$strLength = strlen($text) * $fontWidth;$start = ($imgWidth - $strLength) / 2;imagestring($img, $fontWidth, $start, 30, $text, $black);?>[/code]But it doesn't look centered.I also do [code=php:0]list($imgWidth, $imgHeight, $imgType, $imgAttr) = getimagesize('graphics/speed.gif');[/code] and that makes imgWidth = 50Is my logic for centering incorrect? 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.