2016-03-26 7 views
1

Ich muss etwas Text auf dem Bildschirm als ein Bild mit PHP in einer Seite drucken, aber es zeigt nur ein weißes Quadrat. HierProbleme Ausgabe von Text Bild mit PHP

ist der Code der Hauptseite:

<?php 
    SESSION_START(); 
    if ($_SESSION["log"]!=true){ 
    //die("<h1><center>Non sei loggato come amministratore</center></h1>"); 
    header('location:index.php'); } 

    include('ase.php'); 
    echo (' 
       <!DOCTYPE html> 
       <html> 
       <body> 
       <a href="./logout.php">Logout</a> 
       <img src="data:image/png;base64,' . base64_encode($stringdata) . '"> 
       </body></html>'); 
     ?> 

Und hier der Code der Seite, die ausgeben soll das Bild:

<?php 
    // Set the content-type 
    header('Content-Type: image/png'); 

    // Create the image 
    $im = imagecreatetruecolor(800, 2000); 

    // Create some colors 
    $white = imagecolorallocate($im, 255, 255, 255); 
    $black = imagecolorallocate($im, 0, 0, 0); 
    imagefilledrectangle($im, 0, 0, 800, 2000, $white); 

    // The text to draw 
    $text = "Read the text and the questions below. For each question mark 
    the letter next to the correct answer - A,B,C or D."; 

    // Replace path by your own font path 
    $font = 'arial.ttf'; 


    // Add the text 
    imagettftext($im, 20, 0, 10, 20, $black, $font, $text); 

     ob_start(); 
     imagepng($im); 
     $stringdata = ob_get_contents(); 
     ob_end_clean(); 
    ?> 

(sorry für mein Englisch)

+0

Anstatt (wahrscheinlich, was Sie tun) einschließlich des Skripts und Verwirrung mit der Pufferung der Ausgabe, legen Sie das PHP-Skript als Quelle Bild URL und dann das Bild ausgeben normalerweise ohne Pufferung der Ausgabe. Zerstöre das GD-Objekt nach imagepng mit imagedestroy ($ im); –

+0

Wenn Sie nicht wollen, was Charlotte Dunois vorschlägt (und Sie sollten es tun), entfernen Sie einfach 'header ('Content-Type: image/png');'. – Federkun

+0

Dank @Federico funktioniert es! – ale00

Antwort

0

Ich habe das Problem gelöst, indem ich die Kopfzeile entferne (header('Content-Type: image/png');).