Jump to content

Align text Left for Image create


Gulsaes

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.