note 60689 added to function.imagecolorallocate
| From: | SW at osu1 dot php dot net | Date: | Fri, 13 Jan 2006 22:00:05 +0000 |
| Subject: | note 60689 added to function.imagecolorallocate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101729@lists.php.net to get a copy of this message | ||
This works! A Black-Image with vertical centered white Aliased Arial-Text and same left and right
margin - used for Menu-Buttons.
<?php
function createImgText ($string="", $fontsize=0, $marginX=0, $imgH=0 ,
$fontfile="", $imgColorHex="", $txtColorHex=""){
if($string!=""){
Header("Content-type: image/png");
//
$spacing = 0;
$line = array("linespacing" => $spacing);
$box = @imageftbbox($fontsize,0,$fontfile,$string,$line)
or die("ERROR");
$tw=$box[4]-$box[0]; //image width
$marginY = $imgH - (($imgH - $fontsize) / 2);
$imgWidth = $tw + (2*$marginX);
$im = ImageCreate($imgWidth, $imgH);
$int = hexdec($imgColorHex);
$arr = array("red" => 0xFF & ($int >> 0x10),
"green" => 0xFF & ($int >> 0x8),
"blue" => 0xFF & $int);
$black = ImageColorAllocate($im, $arr["red"], $arr["green"],
$arr["blue"]);
$int = hexdec($txtColorHex);
$arr = array("red" => 0xFF & ($int >> 0x10),
"green" => 0xFF & ($int >> 0x8),
"blue" => 0xFF & $int);
$white = ImageColorAllocate($im, $arr["red"], $arr["green"],
$arr["blue"]);
ImageFtText($im, $fontsize, 0, $marginX, $marginY, $white, $fontfile, $string, array());
ImagePng($im);
ImageDestroy($im);
}else{
echo "ERROR!";
}
}
createImgText ("Hello World", 9, 10, 18, "arial.ttf", "000000",
"FFFFFF");
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagecolorallocate.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60689
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60689&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60689&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60689&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60689&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60689&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60689&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60689&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60689&report=yes
Search -- http://master.php.net/manage/user-notes.php