Gulsaes Posted November 25, 2008 Share Posted November 25, 2008 I'm using the following code to generate images from text, i have got the wrap working but everything is centered, i would like the text aligned left as i'm new to image creation commands i'm stuck. here is what i have function make_wrapped_txt($txt,$filename,$imc_returner,$space = 4, $font = 2, $w = 600) { $int = hexdec($textcolor); $h = imagefontheight($font); $fw = imagefontwidth($font); $txt = explode("\n", wordwrap($txt, ($w / $fw), "\n")); $lines = count($txt); $im = imagecreate($w, (($h * $lines) + ($lines * $space))); $bg = imagecolorallocate($im, 255, 255, 255); if ($imc_returner == "VMC") {$textcolor = imagecolorallocate($im, 0, 0, 0); } elseif ($imc_returner =="MARGINAL") {$textcolor = imagecolorallocate($im, 255, 0, 255); } elseif ($imc_returner =="IMC") {$textcolor = imagecolorallocate($im, 255, 0, 0); } //$textcolor = imagecolorallocate($im, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), // 0xFF & $int); $y = 0; foreach ($txt as $text) { $x = (($w - ($fw * strlen($text))) / 2); imagestring($im, $font, $x, $y, $text, $textcolor); $y += ($h + $space); } $file = "metar_images/" . $filename . ".png"; imagepng($im,$file); echo "<img src= '$file' />"; } Link to comment https://forums.phpfreaks.com/topic/134187-align-text-left-for-image-create/ Share on other sites More sharing options...
Gulsaes Posted November 25, 2008 Author Share Posted November 25, 2008 nevermind, Solved this buy changing the following lines foreach ($txt as $text) { $x = 0; imagestring($im, $font, $x, $y, $text, $textcolor); $y += ($h + $space); } Link to comment https://forums.phpfreaks.com/topic/134187-align-text-left-for-image-create/#findComment-698544 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.