note 53736 deleted from function.imagettfbbox by cmb

From: Date: Sun, 07 Jul 2019 08:10:02 +0000
Subject: note 53736 deleted from function.imagettfbbox by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-211514@lists.php.net to get a copy of this message
Note Submitter: info at rainer-schuetze dot de ---- according function by jtopland at hive dot no 08-Feb-2004 03:26 soukhinov at mail dot ru was right, the function doesn't work with 180°. By the way it was a intresting way to trasform the angle to radian. Change the calculation of the angle to the following: $angle = $angle/ 180 * pi(); The function to calc. the points is correct. Sorry to say this, but the cal. of the height and width is incorrect. I used the version from LB (11-Feb-2004 08:55) /** * return width and height, offset [left, top] of a ttf character * @param string $font : the font file * @param string $text : the character * @param int $size : the font size * @param int $angle : the angle * @access private * @return array of the width and height, left and top. **/ function _getCharacterSize($font, $text, $size, $angle) { // Get the boundingbox from imagettfbbox(), which is correct when angle is 0 $bbox = imagettfbbox($size, 0, $font, $text); // Rotate the boundingbox $angle = $angle/ 180 * pi(); for ($i=0; $i<4; $i++) { $x = $bbox[$i * 2]; $y = $bbox[$i * 2 + 1]; $bbox[$i * 2] = cos($angle) * $x - sin($angle) * $y; // X $bbox[$i * 2 + 1] = sin($angle) * $x + cos($angle) * $y; // Y } // Variables which tells the correct width and height $bbox["left"] = 0- min($bbox[0],$bbox[2],$bbox[4],$bbox[6]); $bbox["top"] = 0- min($bbox[1],$bbox[3],$bbox[5],$bbox[7]); $bbox["width"] = max($bbox[0],$bbox[2],$bbox[4],$bbox[6]) - min($bbox[0],$bbox[2],$bbox[4],$bbox[6]); $bbox["height"] = max($bbox[1],$bbox[3],$bbox[5],$bbox[7]) - min($bbox[1],$bbox[3],$bbox[5],$bbox[7]); return $bbox; }

« previous php.notes (#211514) next »