You are here: Image Generation: Centering Text « PHP « IT news, forums, messages
Image Generation: Centering Text

Posted by Richard Collyer on 05/02/05 18:47

Hello,

I am using the following code.

<?php
$img_number = imagecreate(100,20);
$white = imagecolorallocate($img_number,255,255,255);
$black = imagecolorallocate($img_number,0,0,0);
$grey_shade = imagecolorallocate($img_number,204,204,204);

imagefill($img_number,0,0,$white);

$number = $_GET['text'];

Imagettftext($img_number, 10,0,4,15,$black,'arial.ttf',$number);

header("Content-type: image/jpeg");

$rotate = imagerotate($img_number, 270, 0);

imagejpeg($rotate);

?>

But I need to center the text in the image that is generated. As I am
using the same font and it is fixed at 10px I was thinking of doing
something like:

(Get Length of Text in Chars * Width of Average Char) DIV 2.

(Width of Image DIV 2) - Above = starting point on the x axis.

or can anyone think of a better way to do it?

Cheers
Richard

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация