freaksville Posted November 28, 2009 Share Posted November 28, 2009 Hi, I have created a countdown to Christmas image. Which you can see here: http://count.superscribble.com/christmas/large.php I was wondering if anyone knew how to make the text that GDLib adds to be aligned center? Here is the current code if that helps: <?php $keyMonth = 12; $keyDay = 25; $keyYear = 2009; $month = date(F); $mon = date(n); $day = date(j); $year = date(Y); $hours_left = (mktime(0,0,0,$keyMonth,$keyDay,$keyYear) - time())/3600; $daysLeft = ceil($hours_left/24); $z = (string)$daysLeft; function LoadPNG($imgname) { /* Attempt to open */ $im = @imagecreatefrompng($imgname); /* See if it failed */ if(!$im) { /* Create a blank image */ $im = imagecreatetruecolor(150, 30); $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); /* Output an error message */ imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc); } return $im; } // Setup an image $im = LoadPNG('bg.png'); // Create some colors $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $red_dark = imagecolorallocate($im, 122, 0, 0); $black = imagecolorallocate($im, 0, 0, 0); // Apply the overlay alpha blending flag imagelayereffect($im, IMG_EFFECT_OVERLAY); // The text to draw // Replace path by your own font path $font = 'font.ttf'; // Draw two grey ellipses imagettftext($im, 43, 0, 113, 133, $red_dark, $font, $z); imagettftext($im, 43, 0, 113, 132, $white, $font, $z); // Output header('Content-type: image/png'); imagealphablending($im, true); // setting alpha blending on imagesavealpha($im, true); // save alphablending setting (important) imagepng($im); imagedestroy($im); ?> Thanks in Advance. Link to comment https://forums.phpfreaks.com/topic/183173-gdlib-alignment-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.