1
Я должен напечатать некоторый текст на экране как изображение с PHP на странице, но он отображает только белый квадрат.Проблемы с отображением текстового изображения с PHP
Вот код главной страницы:
<?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>');
?>
А вот код страницы, должен выводить изображение:
<?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();
?>
(простите за мой английский)
Вместо (возможно, что вы делаете), включая скрипт и возиться с буферизацией вывода, установите php-скрипт как URL-адрес источника изображения, а затем выведите изображение нормально без буферизации вывода. Уничтожьте объект GD после 'imagepng' с' imagedestroy ($ im); '. –
Если вы не хотите делать то, что предлагает Шарлотта Дюнуа (и вы должны это сделать), просто удалите 'header ('Content-Type: image/png');'. – Federkun
Благодаря @Federico, он работает! – ale00