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? Link to comment https://forums.phpfreaks.com/topic/27635-length-of-text-for-gd/ 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() Link to comment https://forums.phpfreaks.com/topic/27635-length-of-text-for-gd/#findComment-126389 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? Link to comment https://forums.phpfreaks.com/topic/27635-length-of-text-for-gd/#findComment-126394 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.