Rechenzentrum (RZ)
Organisation
Beratung
Netze
Services
Studium
Software
TUHH
Rechenzentrum
Studium
Grafische Ausgaben mit PHP
PHP-Funktionen:
header
array
ImageCreate
ImageColorAllocate
imagefilledpolygon
ImagePng
ImageDestroy
Quelltext für die Ausgabe von Bild 1:
<?php Header("Content-type: image/png"); $x_size=200; $y_size=80; $points = array( 0 => $x_size*0.1, 1 => $y_size*0.2, 2 => $x_size*0.5, 3 => $y_size*0.1, 4 => $x_size*0.9, 5 => $y_size*0.4, 6 => $x_size*0.5, 7 => $y_size*0.8, 8 => $x_size*0.2, 9 => $y_size*0.75 ); $im = ImageCreate($x_size, $y_size); $yellow = ImageColorAllocate($im, 255, 255 , 0); $red = ImageColorAllocate($im, 255, 0 , 0); imagefilledpolygon($im, $points, 5, $red); ImagePng($im); ImageDestroy($im); ?>
PHP-Funktionen:
header
fopen
fgets
fclose
isset
ImageCreate
ImageColorAllocate
ImageFilledRectangle
ImageLine
ImageString
ImagePng
ImageDestroy
Quelltext für die Ausgabe von Bild 2:
<?php Header("Content-type: image/png"); $x_size=200; $y_size=160; $fd = fopen("xyPoints.txt", "r"); $max_x=$min_x=$max_y=$min_y=0.0; $i=0; while ( $buffer=fgets($fd, 4096) ) { $points[$i]=$buffer; $max_x=max($max_x,$points[$i]); $min_x=min($min_x,$points[$i]); $i++; $points[$i]=fgets($fd, 4096); $max_y=max($max_y,$points[$i]); $min_y=min($min_y,$points[$i]); $i++; } fclose($fd); $i=0; while ( isset ($points[$i]) ) { $points[$i] = 0.15*$x_size+$points[$i]* (0.7*$x_size)/$max_x; $i++; $points[$i] = $y_size - (0.15*$y_size+$points[$i] *(0.7*$y_size)/$max_y); $i++; } $im = ImageCreate($x_size, $y_size); $black = ImageColorAllocate($im, 0, 0 , 0); $red = ImageColorAllocate($im, 255, 0 , 0); $blue = ImageColorAllocate($im, 0, 0 , 255); $turquoise= ImageColorAllocate( $im, HexDec("ae"),HexDec("ff"),HexDec("ff")); ImageFilledRectangle($im, 0 , 0 , $x_size, $x_size, $turquoise); $i=0; while ( isset($points[$i+3]) ) { $x1=$points[$i]; $i++; $y1=$points[$i]; $i++; $x2=$points[$i]; $y2=$points[$i+1]; ImageLine($im, $x1, $y1, $x2, $y2, $red ); } for ($i = 0; $i <= 100; $i=$i+1) { $x1 = 0.15*$x_size+$i*pi()/100*(0.7*$x_size)/pi(); $y1 = $y_size - (0.15*$y_size+sin($i*pi()/100.0)* (0.7*$y_size)) ; $j = $i+1; $x2 = 0.15*$x_size+$j*pi()/100*(0.7*$x_size)/pi(); $y2 = $y_size - (0.15*$y_size+sin($j*pi()/100.0)* (0.7*$y_size)); ImageLine($im, $x1, $y1, $x2, $y2, $blue); } ImageLine($im, 0.15*$x_size, $y_size-0.15*$y_size, 0.85*$x_size, $y_size-0.15*$y_size, $black ); ImageLine($im, 0.15*$x_size, $y_size-0.15*$y_size, 0.15*$x_size, $y_size-0.85*$y_size, $black ); ImageString($im, 3, 0.4*$x_size, 0.9*$y_size, "x-Achse", $blue); ImageStringUp($im, 3, 0.05*$x_size, 0.6*$y_size, "y-Achse", $blue); ImagePng($im); ImageDestroy($im); ?>
Im nachfolgenden Textfenster sehen Sie den Quelltext dieser Beispielseite.
<!--#set var="TITEL" value="Einfuehrung in PHP" --> <!--#set var="KEYWORDS" value="PHP, PHP Tutorial" --> <!--#set var="DESCRIPTION" value="Einfuehrung in PHP" --> <!--#set var="LinkeSeite" value="NOLEFT" --> <!--#set var="SECTION" value="5" --> <!--#include virtual="/rzt/include/bredehoeft.html" --> <!--#include virtual="/rzt/include/rz_header.html" --> <?php require("bin/function_ausgabe.php"); ?> <h2>Grafische Ausgaben mit PHP </h2> <table border="1"> <tr><td> <!-- ======================== Bild 1 wird eingebunden ============================ --> <img src="image1.php" border="1" alt="Bild 1"> <br> PHP-Funktionen: <ul> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.header.html"> header</a><br> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.array.html"> array</a><br> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.imagecreate.html"> ImageCreate</a><br> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.imagecolorallocate.html"> ImageColorAllocate</a><br> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.imagefilledpolygon.html"> imagefilledpolygon</a><br> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.imagepng.html"> ImagePng</a><br> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.imagedestroy.html"> ImageDestroy</a><br> </ul> </td><td> <br>Quelltext für die Ausgabe von Bild 1: <?php $cols=52; ausgabe("image1.php"); ?> </td></tr> <tr><td> <!-- ========================== Bild 2 wird eingebunden =============================== --> <img src="image2.php" border="1" alt="Bild 2"> PHP-Funktionen: <ul> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.header.html"> header</a><br> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.fopen.html"> fopen</a><br> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.fgets.html"> fgets</a><br> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.fclose.html"> fclose</a><br> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.isset.html"> isset</a><br> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.imagecreate.html"> ImageCreate</a><br> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.imagecolorallocate.html"> ImageColorAllocate</a><br> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.imagefilledrectangle.html"> ImageFilledRectangle</a><br> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.imageline.html"> ImageLine</a><br> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.imagestring.html"> ImageString</a><br> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.imagepng.html"> ImagePng</a><br> <li><a href="http://docs.tu-harburg.de/docs/PHP/PHP4-Manual/function.imagedestroy.html"> ImageDestroy</a><br> </ul> </td><td> <br>Quelltext für die Ausgabe von Bild 2: <?php $cols=60; ausgabe("image2.php"); ?> </td></tr> </table> <hr> <?php print "<p>Im nachfolgenden Textfenster sehen Sie den"; print " Quelltext dieser Beispielseite. <br>"; $cols=100; ausgabe($_SERVER["SCRIPT_FILENAME"]); ?> <!--#include virtual="/rzt/include/rz_footer.html" -->