Image string center alignment with GD function

by Prabakaran 2012-08-29 18:23:05

<?php

$width = 400;

$height = 100;

$im = ImageCreate($width, $height);

$bg = ImageColorAllocate($im, 255, 255, 255);

$border = ImageColorAllocate($im, 255, 0, 0);

ImageRectangle($im, 0, 0, $width - 1, $height - 1, $border);

$text = 'Welcome To Hiox Softwares Pvt Ltd';

$textcolor = ImageColorAllocate($im, 255, 0, 0);

$font = 3;


$font_width = ImageFontWidth($font);

$font_height = ImageFontHeight($font);

$text_width = $font_width * strlen($text);

$position_center = ceil(($width - $text_width) / 2);

$text_height = $font_height;

$position_middle = ceil(($height - $text_height) / 2);

$image_string = ImageString($im, $font, $position_center, $position_middle, $text, $textcolor);

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

Imagejpeg($im);

?>
952
like
0
dislike
0
mail
flag

You must LOGIN to add comments