php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1987 ImageTTFBBox does not return correct bounding box.
Submitted: 1999-08-07 02:13 UTC Modified: 1999-08-10 03:05 UTC
From: animate2 at underworld dot net Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.12 OS: Linux 2.2.10
Private report: No CVE-ID: None
 [1999-08-07 02:13 UTC] animate2 at underworld dot net
ImageTTFBBox doesn't return a correct bounding box. In many cases, an image created to be the size of a bounding box will not be tall enough and cuts off part of the text it is meant to contain (in most cases, the bottoms of g's, p's, and other characters with drop-down loopy things). In some occasions, the width of a bounding box will also be inadequate. The following function illustrates:

function GIFheadline ($font, $fontsize, $bulletgif, $text, $number) {
        $bounds = ImageTTFBBox($fontsize, 0, $font, $text);
        $imagewidth = abs($bounds[2] - $bounds[0]);
        $imageheight = abs($bounds[1] - $bounds[7]);
        $image = imagecreate($imagewidth, $imageheight);
        $textcolor = ImageColorAllocate($image, 98,128,190);
        imagettftext($image, $fontsize, 0, 0, $imageheight, $textcolor, $font, $text);
        imagegif($image, "$number.gif");
        }

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-08-10 03:05 UTC] markonen at cvs dot php dot net
ImageTTFBBox behaviour is -- while not too logical -- predictable. Your problem doesn't seem to be the size of
the bounding box, but rather the placement of the string inside that box.

The coordinates returned by the function tell you how much space you need on every side of your initial coordinates. If you get a negative value for the lower right X coordinate, for example, you need to push the string coordinates for ImageTTFText that much forward in order to get the string to fit the image.

Fiddle with it, and contact me if the problem persists. The behaviour is a feature of FreeType, and we can do very little about it.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Oct 10 03:00:01 2026 UTC