note 106206 added to function.imagettftext
| From: | ville dot jungman at gmail dot com | Date: | Tue, 18 Oct 2011 15:34:21 +0000 |
| Subject: | note 106206 added to function.imagettftext | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-183976@lists.php.net to get a copy of this message | ||
<?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'>";
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 83.145.197.172
----
Manual Page -- http://www.php.net/manual/en/function.imagettftext.php
Edit -- https://master.php.net/note/edit/106206
Del: integrated -- https://master.php.net/note/delete/106206/integrated
Del: useless -- https://master.php.net/note/delete/106206/useless
Del: bad code -- https://master.php.net/note/delete/106206/bad+code
Del: spam -- https://master.php.net/note/delete/106206/spam
Del: non-english -- https://master.php.net/note/delete/106206/non-english
Del: in docs -- https://master.php.net/note/delete/106206/in+docs
Del: other reasons-- https://master.php.net/note/delete/106206
Reject -- https://master.php.net/note/reject/106206
Search -- https://master.php.net/manage/user-notes.php