在另一页上显示GD图像

时间:2013-05-19 16:36:16

标签: php ajax gd

我想通过表格为图像添加一些文字..

我对GD没有任何经验,但我已经得到它添加文本,并显示带有标题内容类型的图像...问题是,我只能显示,只有在页面上,没有其他内容...

如果我甚至可以从一个非常棒的ajax调用中返回它,即使我还没有使用ajax ...

代码:

的index.php :::::::

elseif($_GET['p'] == "Images"){
    ?>
    <form action="test.php" method="post">
        <input type="text" name="name" value="">
        <input type="submit" name="submit" value="submit" >
    </form>

    <?php
    if(!isset($_GET['display'])) $_GET['display'] = "false";    
    if($_GET['display'] == "true"){
        echo "<img src='test.php' />";
    }   
}

test.php的:::::

$font = "Images/Pokedex.TTF"; // full path to your font file
$text = $_POST['name'];

$image = imagecreatefrompng("Images/1.png"); 
$color = imagecolorallocate($image, 0, 0, 0);

imagettftext($image, 12, 0, 20, 235, $color, $font, $text);

// define content-type header
header("Content-type: image/png");
// output image as a png image
imagepng($image);
//header("Location:index.php?p=Images&display=true");
// and free the memory 
imagedestroy($image);  

1 个答案:

答案 0 :(得分:1)

您可以在任何html代码中包含<img src='test.php' />,以便在其上获取php生成的图像。您可以使用get param来传递图像测试,如下所示:

<!-- Any HTML code (my be generated by PHP -->
<img src='test.php?name=My+Text' />

对于test.php:

//Replace $text = $_POST['name'];
$text = $_GET['name'];
相关问题