Search This Blog

Monday, March 21, 2011

PHP GD : Centers the text

function getCenterPos($im, $font_size, $font_style, $text) {
    $bbox = imagettfbbox($font_size, 0, $font_style, $text);

    // This is our cordinates for X and Y
    $x = ((imagesx($im) - $bbox[4] - $bbox[0])/2);
    $y = (((imagesy($im)/2)-($bbox[5] - $bbox[1]))/2)-5;

    return array((int)$x, (int)$y);
}

No comments:

Post a Comment