CreateImage Problem

Fragen zu allen Themen rund ums Programmieren außerhalb von phpBB können hier gestellt werden - auch zu anderen Programmiersprachen oder Software wie Webservern und Editoren.
Antworten
Benutzeravatar
witzigerkiller
Gesperrt
Beiträge: 878
Registriert: 05.02.2005 13:27
Wohnort: Sonthofen

CreateImage Problem

Beitrag 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 þ
Bitte keine Anfragen mehr per PN
When you get me on my nerven I put you in the Gully and do the Deckel drüf and you never will come back to the Tageslicht.
Benutzeravatar
witzigerkiller
Gesperrt
Beiträge: 878
Registriert: 05.02.2005 13:27
Wohnort: Sonthofen

Beitrag von witzigerkiller »

*bump it louder*
Bitte keine Anfragen mehr per PN
When you get me on my nerven I put you in the Gully and do the Deckel drüf and you never will come back to the Tageslicht.
progs
Mitglied
Beiträge: 27
Registriert: 02.08.2004 08:49
Wohnort: Wunsiedel
Kontaktdaten:

Beitrag 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.
Antworten

Zurück zu „Coding & Technik“