note 106206 deleted from function.imagettftext by danbrown

From: Date: Tue, 18 Oct 2011 15:42:50 +0000
Subject: note 106206 deleted from function.imagettftext by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183977@lists.php.net to get a copy of this message
Note Submitter: ville dot jungman at gmail dot com ---- <?php ####################################################### # convert text to image and embed it to html # uses /tmp as a cache to make it faster # usage: print imagetext("Hello my friend"); # Created by Ville Jungman, GPL-licenced, donated by www.varuste.net function imagetext($text,$size = 10,$color = array(253,128,46)){ $dir = "/tmp/tekstit"; $filename = "$dir/" . base64_encode($text); if(!file_exists($filename)){ $font = "/usr/share/fonts/truetype/freefont/FreeSans.ttf"; $box = imagettfbbox($size,90,$font,$text); $w = -$box[4] - 1; $h = -$box[3]; $im = imagecreatetruecolor($w,$h); $white = imagecolorallocate($im,$color[1],$color[2],$color[3]); $black = imagecolorallocate($im, 0x00, 0x00, 0x00); imagecolortransparent($im,$white); imagefilledrectangle($im, 0, 0, $size, 99, $white); imagettftext($im,$size,90,$size,$h,$black,$font,$text); @mkdir($dir); imagepng($im,$filename); imagedestroy($im); } $data = base64_encode(file_get_contents($filename)); return "<img src='data:image/png;base64,$data'>"; } ?>

« previous php.notes (#183977) next »