GD - TF Image

Status
Not open for further replies.
PHP:
<?php
header('Content-type: image/png');
$text = $_GET['text'];
$im = imagecreatefrompng ("tech forums.png");
$color = imagecolorallocate($im,30,84,137);
imageAlphaBlending($im, true);
imageSaveAlpha($im, true); 
$font = 'font.ttf';
$fontsize = 24;
$size = imagettfbbox($fontsize, 0, $font, $text); //calculate the pixel of the string
$dx = (imagesx($im)) - (abs($size[2]-$size[0])); //calculate the location to start the text
$dx2 = (imagesx($im)) - (abs($size[2]-$size[0])) - 20; //calculate the location to start the text

imagettftext($im, $fontsize, 0, $dx, 35, imagecolorallocate($im,10,53,97), $font, 'Hey, ');
imagettftext($im, $fontsize, 0, $dx2, 35, $color, $font, $text);
imagepng($im);
imagedestroy($im);
?>

Just keep messing with that values ive changed until it works every time.
 
Actually what i did was pretty stupid. Okay, look through the code, the part that is seperate from the rest in the lower middle, as you can see the $dx is now gone from both those lines, it is replaced by 30 and 100. Change these values until it looks good. It actually should be fine as it is now.

PHP:
<?php
header('Content-type: image/png');
$text = $_GET['text'];
$im = imagecreatefrompng ("tech forums.png");
$color = imagecolorallocate($im,30,84,137);
imageAlphaBlending($im, true);
imageSaveAlpha($im, true); 
$font = 'font.ttf';
$fontsize = 24;

imagettftext($im, $fontsize, 0, 30, 35, imagecolorallocate($im,10,53,97), $font, 'Hey, ');
imagettftext($im, $fontsize, 0, 100, 35, $color, $font, $text);

imagepng($im);
imagedestroy($im);
?>
 
That's great ;)
Thanks for all your help on this guys, you've really saved me alot of time ;)
I'm happy with that now, ;)

Thanks again,

~ Tkey
 
Status
Not open for further replies.
Back
Top Bottom