Seite 1 von 1

CreateImage Problem

Verfasst: 17.02.2006 21:08
von witzigerkiller
Hiho liebe Community,

also ich will für mich eine Umfrage schreiben, die dynamisch die %e als Bild ausgibt, dieses habe ich so gemacht:

Code: Alles auswählen

<?PHP
header('Content-type: image/png'); 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Umfrage</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
  </head>
  <body>
    <?PHP
      $antwort_1 = 25;
      $antwort_2 = 1010;
      $antwort_3 = 2;
      $antwort_4 = 19;
      
      function bild($variable,$a,$b,$c,$d)
      {
        $breite = $variable*100/$a+$b+$c+$d;
        $width = $breite; 
        $height = 200;
        $img = @ImageCreate($width, $height); 
        ImageColorAllocate($img, 255, 0, 0);
        ImageFill($img, 0, 0, $black);
        Imagepng($img); 
      }
      
     echo "Antwort 1: ".bild($antwort_1,$antwort_1,$antwort_2,$antwort_3,$antwort_4)."%<br />";
     echo "Antwort 2: ".bild($antwort_2,$antwort_1,$antwort_2,$antwort_3,$antwort_4)."%<br />";
     echo "Antwort 3: ".bild($antwort_3,$antwort_1,$antwort_2,$antwort_3,$antwort_4)."%<br />";
     echo "Antwort 4: ".bild($antwort_4,$antwort_1,$antwort_2,$antwort_3,$antwort_4)."%<br />";
    ?>
  </body>
</html>
Nur leider kommt das bei raus:

[quote]‰PNG IHDRkÈe þ

Verfasst: 18.02.2006 16:06
von witzigerkiller
*bump it louder*

Verfasst: 18.02.2006 16:32
von progs
Problem liegt darin, dass Du oben per Header definierst, das das ganze ein Bild ist und der Browser das auch als solches behandelt. Jetzt schreibst Du jedoch noch per echo(); irgendwelche Werte in das Bild, welches dadurch falsch ist und nicht mehr gelesen werden kann.

Möglichkeit 1: per imagepng ein Bild erzeugen (imagepng($img, dateiname) und unten per echo(<img>) ausgeben

Möglichkeit 2: Zwei Dateien. Eine image.php mit dem Bild und eine text.php wo Du echo(Antwort1) und echo(<img src="image.php">) machst.