<?php header('Content-type: image/png'); // Start The Image $im = imagecreatetruecolor(400, 200); // Palette $white = imagecolorallocate($im, 255, 255, 255); $gray = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); // Set Color $color = $white; // Background imagefilledrectangle($im, 0, 0, 399, 199, $color); // Words/Font $Font = './fonts/' . $_POST['sel'] . '.ttf'; // Write Text imagefttext($im, 10, 0, 50, 50, $black, $Font,$_POST['word']); // Clearer Text imagepng($im); imagedestroy($im); ?> Code (markup): For some reason whenever I try to go through and make it, it makes the image but it says this: The image "create_img.php" cannot be displayed, because it contains errors. I looked at the PHP manual and there is nothing wrong with mine so I took their example and ran it and got the same error. Is this a PHP version problem or what. How can I fix this answers appreciated.
Try this out <?php ob_start(); header('Content-type: image/png'); // Start The Image $im = imagecreatetruecolor(400, 200); // Palette $white = imagecolorallocate($im, 255, 255, 255); $gray = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); // Set Color $color = $white; // Background imagefilledrectangle($im, 0, 0, 399, 199, $color); // Words/Font $Font = './fonts/' . $_POST['sel'] . '.ttf'; // Write Text imagefttext($im, 10, 0, 50, 50, $black, $Font,$_POST['word']); // Clearer Text imagepng($im); imagedestroy($im); ob_end_flush(); ?> Code (markup):
Used both of your ideas. I think the original error was that it couldn't get to the font file. Works fine now though thanks!
<?php header('Content-type: image/png'); // Start The Image $im = imagecreatetruecolor(400, 200); // Palette $white = imagecolorallocate($im, 255, 255, 255); $gray = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); // Set Color $color = $white; // Background imagefilledrectangle($im, 0, 0, 399, 199, $color); /** * This will check see if the user has selected a font and the fact that it exists.. if all tests are past it will use * the selected font by the user, or else it will use a defualt font that you know exists. * * Simples . */ $Font = (isset($_POST['sel'])&&file_exists('./fonts/'.$_POST['sel'].'.ttf')?'./fonts/'.$_POST['sel'].'.ttf':'defualt.ttf'); // Write Text imagefttext($im, 10, 0, 50, 50, $black, $Font,$_POST['word']); // Clearer Text imagepng($im); imagedestroy($im); ?> PHP: