note 56344 added to function.imagefontwidth

From: Date: Wed, 31 Aug 2005 08:26:10 +0000
Subject: note 56344 added to function.imagefontwidth
Groups: php.notes 
Request: Send a blank email to php-notes+get-94484@lists.php.net to get a copy of this message
a function that is faster than ImageFontWidth for certain uses: <? function ImageFontWidthByFilename($filename) { $handle = @fopen($font_locations[$i],"r"); $c_wid = @fread($handle,11); @fclose($handle); return(ord($c_wid{8})+ord($c_wid{9})+ord($c_wid{10})+ord($c_wid{11})); } echo "./font.gdf is ".ImageFontWidthByFilename("./font.gdf")." pixels wide"; ?> reading the widths of 5 different fonts, 500 times, ImageFontWidth took an average of ~0.004 seconds per 5 reads, my function takes ~0.0003 per 5. The reason is that ImageFontWidth requires a call to ImageLoadFont, but if for some reason you won't need to load the font, just find out the width, this is the function for you :-) more such wonders at http://puremango.co.uk ---- Manual Page -- http://www.php.net/manual/en/function.imagefontwidth.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56344 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56344&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56344&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56344&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56344&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56344&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56344&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56344&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94484) next »