Danzi: bild erzeugen mit php

Beitrag lesen

hallo leute!

ich hab mit php ein bild erzeugt und will nun unter dem bild einen html text anfügen, jedoch funktioniert dass nicht so wie ich es will, da ja der dokumenttyp dann ein gif wird...
kann mir bitte jemand weiterhelfen?

Code:

<?php  
diagramm(10, "1KN:-30:rot, 2KN:20:schwarz, 3KN:5:gruen, 4KN:35:gelb, 5KN:10:lila, 6KN:10:lila, 7KN:10:lila", "m", 350, 200);  
  
function diagramm($abstand, $daten, $einheit, $breite, $hoehe)  
{  
  $schrift = 3;  
  $legende_abstand = 10;  
  
  $daten = explode(", ", $daten);  
  $werte = array();  
  $bezeichnungen = array();  
  $farben = array();  
  
  for($i=0; $i<sizeof($daten); $i++) {  
    $temp = explode(":", $daten[$i]);  
    array_push($bezeichnungen, $temp[0]);  
    array_push($werte, $temp[1]);  
    array_push($farben, $temp[2]);  
    if($abstand_text < imagefontwidth($schrift) * strlen($temp[0]))  
 $abstand_text = imagefontwidth($schrift) * strlen($temp[0]);  
  }  
  
  $abstand_text_h = imagefontheight($schrift);  
  
  $bild = imagecreatetruecolor($breite, $hoehe);  
  
  $farbe_hintergrund = imagecolorexact($bild, 245, 245, 245);  
  $farbe_text = imagecolorexact($bild, 0, 0, 0);  
  $farbe_zwischen = imagecolorexact($bild, 220, 220, 220);  
  
  $farbe_rot = imagecolorexact($bild, 255, 0, 0);  
  $farbe_gruen = imagecolorexact($bild, 0, 255, 0);  
  $farbe_schwarz = imagecolorexact($bild, 0, 0, 0);  
  $farbe_gelb = imagecolorexact($bild, 255, 255, 0);  
  $farbe_lila = imagecolorexact($bild, 255, 0, 255);  
  
  imagefill($bild, 0, 0, $farbe_hintergrund);  
  
  $balken_x = $abstand;  
  $balken_y = $hoehe - $abstand;  
  $balken_b = 2 * $abstand;  
  $diagramm_h = $hoehe - 2 * $abstand;  
  $balken_versatz = 0;  
  
  $legende_x = $balken_x + sizeof($werte) * $balken_b + (sizeof($werte) - 1) * $abstand + 2 * $abstand;  
  $legende_y = $hoehe - $abstand - $legende_abstand;  
  $legende_b = $legende_x + $legende_abstand;  
  $legende_h = $legende_y + $legende_abstand;  
  $legende_versatz = 0;  
  
  for($i=0; $i<sizeof($werte); $i++) {  
    $prozent = 100 / array_sum($werte) * $werte[$i];  
    $balken_h = $diagramm_h / 100 * $prozent;  
  
    $wert = $werte[$i]." ".$einheit;  
  
    $farbe = "farbe_".$farben[$i];  
  
    //imagefilledrectangle($bild, $balken_x + $balken_versatz, $abstand, $balken_x + $balken_versatz + $balken_b, $hoehe - $abstand, $farbe_zwischen);  
    //Diagramm zeichnen  
    imagefilledrectangle($bild, $balken_x + $balken_versatz, $balken_y - $balken_h, $balken_x + $balken_versatz + $balken_b, $balken_y, ${$farbe});  
    imagestring($bild, $schrift, $balken_x + $balken_versatz + 2, $balken_y - $balken_h - $abstand_text_h, $werte[$i], $farbe_text);  
  
    //Legende zeichnen  
    imagefilledrectangle($bild, $legende_x, $legende_y - $legende_versatz, $legende_b, $legende_h - $legende_versatz, ${$farbe});  
    imagestring($bild, $schrift, $legende_x + 2 * $legende_abstand, $legende_y - $legende_versatz, $bezeichnungen[$i], $farbe_text);  
    imagestring($bild, $schrift, $legende_x + 3 * $legende_abstand + $abstand_text, $legende_y - $legende_versatz, $wert, $farbe_text);  
  
    $balken_versatz = $balken_versatz + 3 * $abstand;  
    $legende_versatz = $legende_versatz + 2 * $legende_abstand;  
  }  
  
  header("Content-type: image/gif");  
  imagegif($bild);  
}  
?>

mfg Daniel