note 90481 added to function.imagestring
| From: | eric dot brison at anakeen dot com | Date: | Fri, 24 Apr 2009 07:51:47 +0000 |
| Subject: | note 90481 added to function.imagestring | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153653@lists.php.net to get a copy of this message | ||
Same function as above but it can display multi-line strings.
<?php
function sendimagetext($text) {
// Set font size
$font_size = 4;
$ts=explode("\n",$text);
$width=0;
foreach ($ts as $k=>$string) { //compute width
$width=max($width,strlen($string));
}
// Create image width dependant on width of the string
$width = imagefontwidth($font_size)*$width;
// Set height to that of the font
$height = imagefontheight($font_size)*count($ts);
$el=imagefontheight($font_size);
$em=imagefontwidth($font_size);
// Create the image pallette
$img = imagecreatetruecolor($width,$height);
// Dark red background
$bg = imagecolorallocate($img, 0xAA, 0x00, 0x00);
imagefilledrectangle($img, 0, 0,$width ,$height , $bg);
// White font color
$color = imagecolorallocate($img, 255, 255, 255);
foreach ($ts as $k=>$string) {
// Length of the string
$len = strlen($string);
// Y-coordinate of character, X changes, Y is static
$ypos = 0;
// Loop through the string
for($i=0;$i<$len;$i++){
// Position of the character horizontally
$xpos = $i * $em;
$ypos = $k * $el;
// Draw character
imagechar($img, $font_size, $xpos, $ypos, $string, $color);
// Remove character from string
$string = substr($string, 1);
}
}
// Return the image
header("Content-Type: image/png");
imagepng($img);
// Remove image
imagedestroy($img);
}
?>
----
Server IP: 89.31.146.176
Probable Submitter: 92.129.161.220
----
Manual Page -- http://www.php.net/manual/en/function.imagestring.php
Edit -- https://master.php.net/note/edit/90481
Del: integrated -- https://master.php.net/note/delete/90481/integrated
Del: useless -- https://master.php.net/note/delete/90481/useless
Del: bad code -- https://master.php.net/note/delete/90481/bad+code
Del: spam -- https://master.php.net/note/delete/90481/spam
Del: non-english -- https://master.php.net/note/delete/90481/non-english
Del: in docs -- https://master.php.net/note/delete/90481/in+docs
Del: other reasons-- https://master.php.net/note/delete/90481
Reject -- https://master.php.net/note/reject/90481
Search -- https://master.php.net/manage/user-notes.php