math - help me to write text on the center of image using PHP GD -


this 1 empty image before writing

enter image description here

here code

<?php function loadjpeg($imgname) {     $im = @imagecreatefromjpeg($imgname);      $grey = imagecolorallocate($im, 255, 255, 0);      // text draw     $text = 'http://www.stackoverflow.com';      // replace path own font path     $font = 'consola.ttf';      list($width, $height) = getimagesize($imgname);      // wants know how use width/height dynamically //      imagettftext($im, 20, 45, 200, 450, $grey, $font, $text);      return $im; }  header('content-type: image/jpeg');  $img = loadjpeg('blue_hills.jpg');  imagejpeg($img); imagedestroy($img); ?> 

image after writing text on it

enter image description here

what want vertically , horizontally center text on 45 degree. please me on this. all.

use imagettfbbox function retrieve dimensions text rendering would require. use information calculate x,y coordinate should target within destination image text centered respective width/height.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -