note 94673 added to function.imagettfbbox

From: Date: Tue, 17 Nov 2009 19:26:32 +0000
Subject: note 94673 added to function.imagettfbbox
Groups: php.notes 
Request: Send a blank email to php-notes+get-163002@lists.php.net to get a copy of this message
<?php // script: _autoblocsizer.php // The image bloc is generated to exactly match with your text string, // whatever the font type, the font size, etc. (it works for latin char.) // written by David Ariel Bloomberg - november 2009 // 1. IGNIT : header('Content-type: image/png'); // 2. DEFINE VALUES : // 2.1. Text string to generate (auto or $_GET) if(isset($_GET['str']) and $_GET['str'] != ""){ $text = $_GET['str']; }else{ $text = "Lorem ipsum dolor..."; } // 2.2. Font to be used (auto or $_GET) - TTF only // correct with your own path in place ! if(isset($_GET['font']) and $_GET['font'] != ""){ $font = "../phpFonts/TTF/". $_GET['font'] .".ttf"; }else{ $font = "../phpFonts/TTF/". "bauhausb" .".ttf"; } // 2.3. Font size (auto or $_GET) if(isset($_GET['size']) and $_GET['size'] != ""){ $fontsize = $_GET['size']; }else{ $fontsize = 30; } // 2.4. Angle (auto or $_GET) - Not used in the example... if(isset($_GET['angle']) and $_GET['angle'] != ""){ $angle = $_GET['angle']; }else{ $angle = 0; } // 2.5. Alpha output (auto or $_GET) - Boolean if(isset($_GET['alpha']) and $_GET['alpha'] == "TRUE"){ $_alpha = "TRUE"; }else{ $_alpha = "FALSE"; } // 3. CALCULATE BOX DIMENSIONS : (imagettfbbox) $zh = imagettfbbox($fontsize, $angle, $font, $text); $zh_0 = $zh[0]; $zh_1 = $zh[1]; $zh_2 = $zh[2]; $zh_3 = $zh[3]; $zh_4 = $zh[4]; $zh_5 = $zh[5]; $zh_6 = $zh[6]; $zh_7 = $zh[7]; $textbloc_width = ($zh_4 - $zh_6); $textbloc_height = ($zh_1 -($zh_7) ); $textbloc_marginleft = ($zh_6 +1); // +1 is a correction to match math with reality $textbloc_marginright = $textbloc_marginleft; $bloc_v_margin = $textbloc_marginleft; // for layout, to have equal margins on the 4 sides $textbloc_up_low_char = $zh_3; $BLOCwidth = ($textbloc_width +$textbloc_marginleft +$textbloc_marginright); $BLOCheight = ($textbloc_height +($bloc_v_margin *2)); $top_distance = ($BLOCheight -($textbloc_up_low_char +$bloc_v_margin) ); // 4. CREATE THE NEW PNG IMAGE: // 4.1. PREPARING BLOC : (imagecreatetruecolor) with alpha option $im = imagecreatetruecolor($BLOCwidth, $BLOCheight); // 4.2. OPTION WITH PROCESS THAT MAKES A TRUE TRANSPARENCY WITH PERFECT ANTIALIASING! if($_alpha == "TRUE"){ imagealphablending($im, false); $colorTransparent = imagecolorallocatealpha($im, 0, 0, 0, 127); imagefill($im, 0, 0, $colorTransparent); imagesavealpha($im, true); } // 4.3. define some colors : $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); $C25ACC7 = imagecolorallocate($im, 37, 172, 199); $C69C7DD = imagecolorallocate($im, 105, 199, 221); // 4.4. THIS PROCESS IS REQUIRED ONLY FOR NON-TRANSPARENCY PROCESS! if($_alpha != "TRUE"){ imagefilledrectangle($im, 0, 0, $BLOCwidth, $BLOCheight, $C69C7DD); } // 4.5. GENERATING THE TEXT STRING... imagettftext($im, $fontsize, 0, 0, $top_distance, $C25ACC7, $font, $text); // 5. Output to browser imagepng($im); imagedestroy($im); ?> ---- Server IP: 92.48.74.199 Probable Submitter: 81.39.35.111 ---- Manual Page -- http://www.php.net/manual/en/function.imagettfbbox.php Edit -- https://master.php.net/note/edit/94673 Del: integrated -- https://master.php.net/note/delete/94673/integrated Del: useless -- https://master.php.net/note/delete/94673/useless Del: bad code -- https://master.php.net/note/delete/94673/bad+code Del: spam -- https://master.php.net/note/delete/94673/spam Del: non-english -- https://master.php.net/note/delete/94673/non-english Del: in docs -- https://master.php.net/note/delete/94673/in+docs Del: other reasons-- https://master.php.net/note/delete/94673 Reject -- https://master.php.net/note/reject/94673 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#163002) next »