Ich habe in image_creator Code zum Erstellen von Bildern.
<?php
header("Content-Type: image/jpeg");
$im = ImageCreateFromGif("photo.gif");
$black = ImageColorAllocate($im, 255, 255, 255);
$start_x = 10;
$start_y = 20;
Imagettftext($im, 12, 0, $start_x, $start_y, $black, 'verdana.ttf', "text to write");
Imagejpeg($im, '', 100);
ImageDestroy($im);
?>
Die Datei für die Bildausgabe lautet image.php und hat folgenden Code
<html>
<head>
</head>
<body>
<img src="http://localhost/image_creator.php"/>
</body>
</html>
Wenn ich image.php starte, bekomme ich nur eine leere Seite. Wieso ist es so?
Verwenden Sie diese Option, um Text zum Bild hinzuzufügen (kopiert aus PHP für Kinder ).
<?php
//Set the Content Type
header('Content-type: image/jpeg');
// Create Image From Existing File
$jpg_image = imagecreatefromjpeg('sunset.jpg');
// Allocate A Color For The Text
$white = imagecolorallocate($jpg_image, 255, 255, 255);
// Set Path to Font File
$font_path = 'font.TTF';
// Set Text to Be Printed On Image
$text = "This is a sunset!";
// Print Text On Image
imagettftext($jpg_image, 25, 0, 75, 300, $white, $font_path, $text);
// Send Image to Browser
imagejpeg($jpg_image);
// Clear Memory
imagedestroy($jpg_image);
?>
Problem hier ist
$black = ImageColorAllocate($im, 255, 255, 255);
dies nicht schwarz, sondern weiß. Für Schwarz sollte es so sein,
$black = ImageColorAllocate($im, 0, 0, 0);
Das Problem hier ist: $black = ImageColorAllocate($im, 255, 255, 255);
// <== das nicht schwarz ist, es ist weiß.
$black = ImageColorAllocate($im, 0, 0, 0);