Right align text in an image with imagettftext(), PHP
        Posted  
        
            by James Simpson
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by James Simpson
        
        
        
        Published on 2010-03-14T22:20:26Z
        Indexed on 
            2010/03/14
            22:25 UTC
        
        
        Read the original article
        Hit count: 244
        
I am setting up dynamic forum signature images for my users and I want to be able to put their username on the image. I am able to do this just fine, but since usernames are different lengths and I want to right align the username, how can I go about doing this when I have to set x & y coordinates.
$im = imagecreatefromjpeg("/path/to/base/image.jpg");
$text = "Username";
$font = "Font.ttf";
$black = imagecolorallocate($im, 0, 0, 0);
imagettftext($im, 10, 0, 217, 15, $black, $font, $text);
imagejpeg($im, null, 90);
© Stack Overflow or respective owner