note 64654 deleted from function.imagettftext by cmb

From: Date: Sun, 13 Jan 2019 10:38:50 +0000
Subject: note 64654 deleted from function.imagettftext by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210045@lists.php.net to get a copy of this message
Note Submitter: ugo dot quaisse at gmail dot com ---- This is a script that aim at center the (multi) lines : <?php header("Content-type: image/png"); //1line per column $text=array(0=>"line 1",1=>"line 2"); $largeur=500; $line_height=30; $hauteur=sizeof($text)*$line_height; // Create the image $im = imagecreatetruecolor($largeur, $hauteur); // Create some colors $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 225, 225, 225); $blue = imagecolorallocate($im, 0, 62, 126); imagefilledrectangle($im, 0, 0, $largeur, $hauteur, $white); // Replace path by your own font path $font = 'font.ttf'; for($i=0;$i<=sizeof($text);$i++) { //Center the text $size = imagettfbbox(20, 0, $font, $text[$i]); $long_text = $size[2]+$size[0]; $posx=($largeur-$long_text)/2; // Add the text imagettftext($im, 20, 0, $posx, $line_height+$line_height*$i, $blue, $font, $text[$i]); } imagepng($im); imagedestroy($im); ?>

« previous php.notes (#210045) next »