Hi!
I played around with that multi-line-script "makeImageF".
Added some features, mainly: you can read text-files
or add text as parameter - eg :
imagettftext.php?file=test.txt
imagettftext.php?text=hello|world!
have fun!
======================================
<?php
$type = $_REQUEST['type'] ? $_REQUEST['type'] : "png";
switch($type) {
case "gif" :
header("Content-type: image/gif");
imageGIF(imagettfpostext($text, $font,
$fsize, $pos, $rgb),"wm.gif", 9); break;
case "png" :
header("Content-type: image/png");
imagePNG(imagettfpostext($text, $font,
$fsize, $pos, $rgb),"wm.png", 9); break;
}
function rgb2hex($rgb) {
$color = array("black"=>"#000", "grn"=>"#090",
"red"=>"#f00", "blu"=>"00f");
$trans = array("a"=>"10", "b"=>"11", "c"=>"12",
"d"=>"13", "e"=>"14", "f"=>"15");
$hex = array();
$rgb = str_replace("#","",
str_replace(array_keys($color), array_values($color), strtolower($rgb)));
for ($x=0; $x<strlen($rgb); $x++)
$hex[] = strtr($rgb[$x],$trans);
if (count($hex)==3) {
$hex[5] = $hex[2]; $hex[4] = $hex[2];
$hex[3] = $hex[1]; $hex[2] = $hex[1];
$hex[1] = $hex[0];
};
$hex = ($hex[0]*16+$hex[1])
."x".($hex[2]*16+$hex[3])
."x".($hex[4]*16+$hex[5]);
return $hex;
}
$file = $_GET['file']
? $_GET['file'] : "logo.txt";
if ($_GET['file']) {
$fp = @fopen($file, "r");
while (!feof($fp)) $text .= fgets($fp); fclose($fp);
} else $text = str_replace("|","\n",$_GET['text']);
$pos = $_GET['pos']
? $_GET['pos'] : 0;
$font = $_GET['font']
? "./fonts/".$_GET['font'].".ttf" : "./fonts/verdana.ttf";
$fsize = $_GET['fsize']
? $_GET['fsize'] : 12;
$rgb = $_GET['rgb']
? $_GET['rgb'] : "#ff9,#393";
imagepng(imagettfpostext($text, $font, $fsize, $pos, $rgb));
function imagettfpostext($text, $font, $fsize, $pos, $rgb,
$Leading=0, $W=0, $H=0, $X=0, $Y=0) {
$angle = 0;
$_bx = imageTTFBbox($fsize,0,$font,$text);
$str = split("[\n]+",$text);
$nL = count($str);
$W = ($W==0)
? abs($_bx[2]-$_bx[0])
: $W;
$H = ($H==0)
? abs($_bx[5]-$_bx[3])+($nL>1
? ($nL*$Leading)
: 0)
: $H;
$im = @imagecreate($W, $H)
or die("Cannot Initialize new GD image stream");
$rgb = explode(",",$rgb);
$tc = explode("x",rgb2hex($rgb[1]));
$bc=explode("x",rgb2hex($rgb[0]));
$bc = imagecolorallocate($im, $bc[0], $bc[1], $bc[2]);
$tc = imagecolorallocate($im, $tc[0], $tc[1], $tc[2]);
if ($pos == 0) {
imagettftext($im, $fsize, $angle, $X,
$fsize, $tc, $font, $text);
} else {
$alpha = range("a", "z");
$alpha = $alpha.strtoupper($alpha).range(0, 9);
$_b = imageTTFBbox($fsize, 0, $font, $alpha);
$_H = abs($_b[5]-$_b[3]);
$__H = 0;
for ($i=0; $i<$nL; $i++) {
$_b = imageTTFBbox($fsize, 0, $font, $str[$i]);
$_W = abs($_b[2]-$_b[0]);
if ($pos == 1) $_X = $W-$_W;
else $_X = abs($W/2)-abs($_W/2);
$__H += $_H;
imagettftext($im, $fsize, $angle, $_X, $__H,
$tc, $font, $str[$i]);
$__H += $Leading;
}
}
if ($_REQUEST["trans"]) {
$bg_color = ImageColorAt($im,1,1);
ImageColorTransparent($im, $bg_color);
}
return $im;
}
?>