Hallo,
ich habe kürzlich angefangen mich mit PHP zu befassen und habe mein erstes Projekt gestartet. Mein Ziel ist es ein Eingabeformular zu erstellen, in welchem man einen beliebigen Text, die Textfarbe, Schriftart, Hintergrund und gespiegelten Text eingeben kann und nach dem Absenden soll auf der Formularseite das erzeugte GIF angezeigt werden.
In meinem script funktioniert die GIF-Ausgabe mit dem eingegebenen Text, allerdings nur mit vordefinierten Farben, sprich, meine Auswahlfunktion für die Farbe funktioniert nicht und ich habe keine Idee warum.
Vielleicht kann mir einer von euch auf die Sprünge helfen.
HTML:
PHP-Code:
<html>
<head>
</head>
<body>
<?php
$mytext=$_POST['mytext'];
if(isset($mytext)){print '<img src="image-gif.php?mytext=' . $mytext . '">';}
?>
<table width="654" border="1" align="center" cellpadding="3" cellspacing="0" bgcolor="#ffffff">
<tr>
<td align='center'><b><h2>Texteingabe</h2></b></td>
</tr>
</table>
<table width="650" border="1" align="center" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
<tr>
<form name="form" method="post" action="mytext.php">
<td>
<table width="650" border="0" cellpadding="3" cellspacing="1" bgcolor="#ffffff">
<tr>
<td><b>Bildausgabe</b></td>
</tr>
<tr>
<td><input name="mytext" type="text" size="100" maxlength="100"></td>
</tr>
<tr>
<td>
Schriftfarbe auswählen:
<p>
<select name="textcolor" size="4">
<option style="background: #FF0000" value="rot" selected>rot</option>
<option style="background: #FFFF00" value="gelb">gelb</option>
<option style="background: #00FF00" value="grün">grün</option>
<option style="background: #0000FF" value="blau">blau</option>
</select>
</p>
<br>
Schriftart auswählen:
<p>
<input type="radio" name="font" value="Agate Bold" checked> Agate Bold<br>
<input type="radio" name="font" value="AirstreamNF"> AirstreamNF<br>
<input type="radio" name="font" value="Allegro_BT"> Allegro_BT
</p>
<br>
Gespiegelter Text für die Verklebung hinter der Scheibe:
<p>
<input type="checkbox" name="gespiegelt" value="gespiegelt"> gespiegelt<br>
</p>
</td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit" value="Reset"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>
PHP:
PHP-Code:
<?php
header("Content-type: image/gif");
$mytext = $_GET['mytext'];
$fontsize = 5;
$wide = imagefontwidth($fontsize) * strlen($mytext) + 20;
$high = imagefontheight($fontsize) + 20;
$picture = imagecreatetruecolor($wide,$high);
$gray = imagecolorallocate($picture,223,223,223);
$textcolor = $_GET['textcolor'];
switch($textcolor) {
case 'rot': $color = imagecolorallocate($picture,255,0,0);
break;
case 'gelb': $color= imagecolorallocate($picture,255,255,0);
break;
case 'grün': $color = imagecolorallocate($picture,0,255,0);
break;
case 'blau': $color = imagecolorallocate($picture,0,0,255);
break;
}
imagefill($picture,0,0,$gray);
$black=imagecolorallocate($picture, 0, 0, 0);
imageline($picture, 0, 0, 0, $high, $black);
imageline($picture, 0, 0, $wide, 0, $black);
imageline($picture, $wide-1, 0, $wide-1, $high-1, $black);
imageline($picture, 0, $high-1, $wide-1, $high-1, $black);
imagestring($picture,$fontsize,10,10,$mytext,$color);
imagegif($picture);
imagegif($picture,"mytextpic.gif");
imagedestroy($picture);
?>