Create text on image in center using php imagettfbbox

Using imagedestroy, imagejpeg, imagettftext, imagettfbbox, imagefill, hexdec, imagesx, imagesy, strtoupper, font, imagecreatetruecolor, Create text image in image center.


imagettfbbox() Function return array index values means
0 - lower left corner, X position
1 - lower left corner, Y position
2 - lower right corner, X position
3 - lower right corner, Y position
4 - upper right corner, X position
5 - upper right corner, Y position
6 - upper left corner, X position
7 - upper left corner, Y position

createTextImage.php
<?php
$text=strtoupper('P');

$imgWidth = 53;
$imgHeight = 53;
$font = './calibri.ttf';
$fontSize = 12;
$angle = 8;
$imageColor=hexdec("#48A201");
$textColor=hexdec("#FF0000");

$txtImg = imagecreatetruecolor($imgWidth, $imgHeight); 
imagefill($txtImg,0,0,$imageColor);

$xi = imagesx($txtImg);
$yi = imagesy($txtImg);

$textLayout = imagettfbbox($fontSize, $angle, $font, $text);
$xr = abs(max($textLayout[2], $textLayout[4]))+5;
$yr = abs(max($textLayout[5], $textLayout[7]));

$newX = intval(($xi - $xr) / 2);
$newY = intval(($yi + $yr) / 2);

imagettftext($txtImg, $fontSize, 0, $newX, $newY, $textColor, $font, $text);
imagejpeg($txtImg,'img/xx.jpg',90);
imagedestroy($txtImg);

?>

Comments

  1. El Yucateco - Casino, Restaurants & Rooms - Mapyro
    Find 문경 출장안마 your ideal location 양주 출장샵 in 창원 출장안마 Las Vegas, NV 아산 출장샵 with Mapyro, the best Las Vegas 충청북도 출장샵 location guide.

    ReplyDelete

Post a Comment

Popular posts from this blog

Login with facebook using coldfusion

Create CSV file in Coldfusion Using CFFile

Get Previous One Day Data in Sql Server