note 96908 added to function.imagettftext

From: Date: Mon, 22 Mar 2010 15:43:49 +0000
Subject: note 96908 added to function.imagettftext
Groups: php.notes 
Request: Send a blank email to php-notes+get-167296@lists.php.net to get a copy of this message
Because the text generated this way is not the same quality in all resolutions, i thought about a method to make it best quality without high resolution. So i wrote this simple code wich should do something like multisampling... Here it is (the $iMultiSampling parameter is the quality - multiplicator of multisampling): <?php function imagettftextmultisampled(&$hImg, $iSize, $sAngle, $iX, $iY, $cColor, $sFont, $sText, $iMultiSampling){ $iWidth = imagesx($hImg); $iHeight = imagesy($hImg); $hImgCpy = imagecreatetruecolor(ceil($iWidth*$iMultiSampling), ceil($iHeight*$iMultiSampling)); $cColor = imagecolorsforindex($hImg, $cColor); $cColor = imagecolorallocatealpha($hImgCpy, $cColor['red'], $cColor['green'], $cColor['blue'], $cColor['alpha']); imagesavealpha($hImgCpy, true); imagealphablending($hImgCpy, false); $cTransparent = imagecolortransparent($hImgCpy, imagecolorallocatealpha($hImgCpy, 0, 0, 0, 127)); imagefill($hImgCpy, 0, 0, $cTransparent); $aBox = imagettftext($hImgCpy, $iSize*$iMultiSampling, $sAngle, ceil($iX*$iMultiSampling), ceil($iY*$iMultiSampling), $cColor, $sFont, $sText); imagecopyresampled($hImg, $hImgCpy, 0, 0, 0, 0, $iWidth, $iHeight, ceil($iWidth*$iMultiSampling), ceil($iHeight*$iMultiSampling)); imagedestroy($hImgCpy); foreach($aBox as $iKey => $iCoordinate) $aBox[$iKey] = $iCoordinate/$iMultiSampling; return($aBox); } function imagettfbboxmultisampled($iSize, $iAngle, $sFont, $sText, $iMultiSampling){ $aBox = imagettfbbox($iSize*$iMultiSampling, $iAngle, $sFont, $sText); foreach($aBox as $iKey => $iCoordinate) $aBox[$iKey] = $iCoordinate/$iMultiSampling; return($aBox); } ?> ---- Server IP: 217.160.235.204 Probable Submitter: 93.219.187.138 ---- Manual Page -- http://www.php.net/manual/en/function.imagettftext.php Edit -- https://master.php.net/note/edit/96908 Del: integrated -- https://master.php.net/note/delete/96908/integrated Del: useless -- https://master.php.net/note/delete/96908/useless Del: bad code -- https://master.php.net/note/delete/96908/bad+code Del: spam -- https://master.php.net/note/delete/96908/spam Del: non-english -- https://master.php.net/note/delete/96908/non-english Del: in docs -- https://master.php.net/note/delete/96908/in+docs Del: other reasons-- https://master.php.net/note/delete/96908 Reject -- https://master.php.net/note/reject/96908 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167296) next »