note 39808 deleted from function.imagettfbbox by cmb

From: Date: Sun, 04 Dec 2016 12:01:37 +0000
Subject: note 39808 deleted from function.imagettfbbox by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208173@lists.php.net to get a copy of this message
Note Submitter: LB ---- the oliver dot martin at onemail dot fixbbox function is just lacking a small thing: the coordonates for top and left have to be the opposite, because the imagettftext x and y coordonates are calculated from the top left of the image and set the bottom left of the first character. The correct function is: function fixbbox($bbox) { $tmp_bbox["left"] = min($bbox[0],$bbox[2],$bbox[4],$bbox[6]); $tmp_bbox["top"] = min($bbox[1],$bbox[3],$bbox[5],$bbox[7]); $tmp_bbox["width"] = max($bbox[0],$bbox[2],$bbox[4],$bbox[6]) - min($bbox[0],$bbox[2],$bbox[4],$bbox[6]) + 1; $tmp_bbox["height"] = max($bbox[1],$bbox[3],$bbox[5],$bbox[7]) - min($bbox[1],$bbox[3],$bbox[5],$bbox[7]); $tmp_bbox["left"] = 0 - $tmp_bbox["left"]; $tmp_bbox["top"] = 0 - $tmp_bbox["top"]; return $tmp_bbox; } And it works for any rotated text.

« previous php.notes (#208173) next »