salve ragazzi,
ho un piccolo problema con questo script
per la creazione di una imagine con testo solo che nn so come aggiungere una variabile per il cambio del colore dello sfondo e del colore della scritta
lo script lo potete provare QUI
mentre questo e il codice
text_admin.php
Codice PHP:
<?php
/**
* dynTEXTmaker - Generate dynamic text buttons on the fly
*
* @version 0.1
* @copyright 19.08.2003
* @author Marc Giombetti <marc@giombetti.com>
*
*/
include("text_config.inc.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Dynamic text-graphic generator</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p><font size="4" face="Verdana, Arial, Helvetica, sans-serif">Dynamic text-graphic generator</font></p>
<form name="form" method="post" action="<?=$_SERVER['PHP_SELF'];
?>">
<?php
if($_POST['send'] == "true"){
$noedit = $_POST['text'];
$edit = urlencode($_POST['text']);
if($usekinkyurl == "1"){
$urlhtml = "<img src=\"${tmurl}text.php/text/$edit/s/${_POST['s']}/pic.png\">";
$url = "${tmurl}text.php/text/$edit/s/${_POST['s']}/pic.png";
echo "<br>
<img src=\"${tmurl}text.php/text/$edit/s/${_POST['s']}/pic.png\"><br><br>
<strong>HTML code</strong>
<textarea name=\"textarea\" cols=\"100\" rows=\"2\">$urlhtml</textarea><br><br>
<strong>Image URL</strong>
<textarea name=\"textarea\" cols=\"100\" rows=\"2\">$url</textarea><br><br>
<br>";
}else{
$urlhtml = "<img src=\"${tmurl}text.php?text=$edit&s=${_POST['s']}\">";
$url = "${tmurl}text.php?text=$edit&s=${_POST['s']}";
echo "<br>
<img src=\"text.php?text=$edit&s=${_POST['s']}\"><br><br>
<strong>HTML code</strong>
<textarea name=\"textarea\" cols=\"100\" rows=\"2\">$urlhtml</textarea><br><br>
<strong>Image URL</strong>
<textarea name=\"textarea\" cols=\"100\" rows=\"2\">$url</textarea><br><br>
<br>";
}
}
?>
<strong>Text:</strong>
<input name="text" type="text" value="<?=$noedit;?>" size="40"><br>
<strong>Textsize (pixels):</strong>
<select name="s">
<?php
if(isset($_POST['s'])){
$sizedefault = $_POST['s'];
}
for($i=$sizemin;$i<=$sizemax;$i++){
if($i == $sizedefault){
echo "<option value=\"$i\" selected>$i</option>";
}else{
echo "<option value=\"$i\">$i</option>";
}
}
?>
</select>
<input name="Generate" type="submit" id="Generiate" value="Generate">
<input name="send" type="hidden" id="send" value="true">
<br>
</form>
<p> </p>
</body>
</html>
text.php
Codice PHP:
<?php
/**
* dynTEXTmaker - Generate dynamic text buttons on the fly
*
* @version 0.1
* @copyright 19.08.2003
* @author Marc Giombetti <marc@giombetti.com>
*
*/
include("text_config.inc.php");
if(isset($PATH_INFO) && $usekinkyurl == "1"){
$vardata = explode('/', $PATH_INFO);
$num_param = count($vardata);
if($num_param % 2 == 0){
$vardata[] = '';
$num_param++;
}
for($i = 1; $i < $num_param; $i += 2){
$$vardata[$i] = $vardata[$i + 1];
}
$text = urldecode($text);
}else{
$text = urldecode($_GET['text']);
$s = $_GET['s'];
}
if(empty($s) || !is_numeric($s)){
$s = $sizedefault;
}else{
if($s < $sizemin){
$s = $sizemin;
}
if($s > $sizemax){
$s = $sizemax;
}
}
if(empty($text)){
$text = $text_default;
}
/**
* hex2dec()
*
* @param string $hex Hexadecimal color
* @return array array('r','g','b')
*/
function hex2dec($hex){
$color = str_replace('#', '', $hex);
$ret = array(
'r' => hexdec(substr($color, 0, 2)),
'g' => hexdec(substr($color, 2, 2)),
'b' => hexdec(substr($color, 4, 2))
);
return $ret;
}
if($usecache == 1){
$cachestring = md5("$$bg_color|$text_color|$text|$font|$s");
$imcache = @ImageCreateFromPNG ("$cachefolder$cachestring.png");
if($imcache){
ImagePNG($imcache);
}else{
Header("Content-type: image/png");
$size = imagettfbbox($s, 0, $font, $text);
$dx = abs($size[2] - $size[0]);
$dy = abs($size[5] - $size[3]);
$xpad = 9;
$ypad = 9;
$im = imagecreate($dx + $xpad, $dy + $ypad);
$bgc = hex2dec($bg_color);
$bg = ImageColorAllocate($im, $bgc['r'], $bgc['g'], $bgc['b']);
$mac = hex2dec($text_color);
$main = ImageColorAllocate($im, $mac['r'], $mac['g'], $mac['b']);
ImageTTFText($im, $s, 0, (int)($xpad / 2), $dy + (int)($ypad / 2)-1, $main, $font, $text);
ImagePng($im, "$cachefolder$cachestring.png");
$imcache = @ImageCreateFromPNG ("$cachefolder$cachestring.png");
ImagePNG($imcache);
}
}else{
Header("Content-type: image/png");
$size = imagettfbbox($s, 0, $font, $text);
$dx = abs($size[2] - $size[0]);
$dy = abs($size[5] - $size[3]);
$xpad = 9;
$ypad = 9;
$im = imagecreate($dx + $xpad, $dy + $ypad);
$bgc = hex2dec($bg_color);
$bg = ImageColorAllocate($im, $bgc['r'], $bgc['g'], $bgc['b']);
$mac = hex2dec($text_color);
$main = ImageColorAllocate($im, $mac['r'], $mac['g'], $mac['b']);
ImageTTFText($im, $s, 0, (int)($xpad / 2), $dy + (int)($ypad / 2)-1, $main, $font, $text);
ImagePng($im);
ImageDestroy($im);
}
?>
text_config.inc.php
Codice PHP:
<?php
/**
* dynTEXTmaker - Generate dynamic text buttons on the fly
*
* @version 0.1
* @copyright 19.08.2003
* @author Marc Giombetti <marc@giombetti.com>
*
*/
$sizemax = 50; //Maximal height the text can have
$sizemin = 10; //Minimal height the text can have
$sizedefault = 15; //If no height is set, use the following
$font = "fonts/spacecowboy.ttf"; //The font to use
$usekinkyurl = 1; //Shall the url be of the type /text.php/text/Hello+World/s/15/pic.png (doesn't work if PHP is used as CGI)
$tmurl = "http://www.giombetti.com/textmaker/"; //URL to dynTEXTmaker
$bg_color = "#90AB83"; //Hexadecimal value of the background color
$text_color = "#24570B"; //Hexadecimal value of the text color
$text_default = "No text specified"; //Default text that is shown if no text is specified
$usecache = 1; //Shall we use cache or not (cacheing is important to improve speed and to reduce high server loads
$cachefolder = "cache/" //If cacheing is enabled, where shall the cached data be stored
?>
grazie