math - help me to write text on the center of image using PHP GD -
this 1 empty image before writing
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
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
Post a Comment