note 101675 deleted from function.imagexbm by danbrown

From: Date: Tue, 04 Jan 2011 14:44:43 +0000
Subject: note 101675 deleted from function.imagexbm by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-175444@lists.php.net to get a copy of this message
Note Submitter: Don Jones ---- There are 2 errors on this page in the examples. No one points out that the width MUST be evenly divisible by 8 or you get a mess. The example is 120 wide which just accidentally is evenly divisible by 8, which will happen only 1 in 8 times, randomly. This issue is dealt with in the code below. Also, since xbm is not color but black and white, the example should not be showing color anything, but it does. The code below is for black and white, and it works great. I love your site!!! <?php header("Content-type: image/xbm"); $mytext = $_GET['mytext']; $fontsize = 5; $wide = imagefontwidth($fontsize) * strlen($mytext) + 20; $temp1=$wide/8; $temp2=round($wide/8); if ($temp1<>$temp2){$wide=($temp2 * 8) + 8;} $high = imagefontheight($fontsize) + 20; $picture = imagecreatetruecolor($wide,$high); $white = imagecolorallocate($picture,255,255,255); imagefill($picture,0,0,$white); $black=imagecolorallocate($picture, 0, 0, 0); imageline($picture, 0, 0, 0, $high, $black); imageline($picture, 0, 0, $wide, 0, $black); imageline($picture, $wide-1, 0, $wide-1, $high-1, $black); imageline($picture, 0, $high-1, $wide-1, $high-1, $black); imagestring($picture,$fontsize,10,10,$mytext,$black); imagexbm($picture); imagexbm($picture,"mytextpic.xbm"); imagedestroy($picture); ?>

« previous php.notes (#175444) next »