开发者社区> 问答> 正文

php 使用echo就报错.... ?报错

刚开始学php,写了一段文字生成图片的代码。现在发现不能将text传至php里,而且就算不传参。直接在php里定义$ment = $POST['text'] 也会报错:图像xxx因存在错误无法显示,肯定不是字体的问题,我快疯了..谁能帮帮我...代码如下
index.html:

 <html>
    <head>
        <title>Logo Generater</title>
    </head>
    <body>
        <form method="post" action="logo generate.php">
        <label for="text">Company name:</label>
        <input type="text" name="text" id="text"/>
        <input type="submit" name="submit" id="submit" value='OK'>
        </form>
    </body>
</html>

logo generate.php:

<?php
$ment = 'What are you 弄啥类?'
$ment = $_POST['text'];
echo $ment;
echo strlen($ment);
$im = imagecreate(450,50);
$white = imagecolorallocate($im,0,0,0);
#imagecolortransparent($im,$white); 
$black = imagecolorallocate($im,255, 255,255);
imagettftext($im,26,0,15,40,$black,'E:\xampp\htdocs\test\simsun.ttc',$ment);
header("Content-type:image/png");
imagepng($im);
?>

谢谢了...
-------------------------16:35更新-----------------------
谢谢帮助我的人~(づ ̄ 3 ̄)づ
还有个问题 能不能像这张图一样,点击OK,传参给PHP,之后还在这个界面显示图片图片说明
以下是新代码~

 <html>
    <head>
        <title>Logo Generater</title>
    </head>
    <body>
        <form  action="logo generate.php" method="post">
        <h1>Logo Generater</h1>
        <h2>wirte by Yates WANG</h2>
        <label for="ment">Company name:</label>
        <input type="text" name="ment" id="ment"/>
        <input type="submit" name="submit" id="submit" value='OK'>
        <br/>
        <br/>
        <img src="logo generate.php" />
        <form>
    </body>
</html>
 <?php
#$ment = 'What are you 弄啥类?';
$ment = $_POST['ment'];
#echo strlen($ment);
#$len = strlen($ment) * 30;
$im = imagecreate(400,50);
$white = imagecolorallocate($im,0,0,0);
#imagecolortransparent($im,$white); 
$black = imagecolorallocate($im,255, 255,255);
imagettftext($im,26,0,15,40,$black,'C:\Windows\Fonts\simsun.ttc',$ment);
header("Content-type:image/png");
imagepng($im);
imagedestroy($im);
?>

再次感谢!

展开
收起
爱吃鱼的程序员 2020-06-23 13:45:30 667 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
    <inputtype="text"name="text"id="text"/>

    这是文本,怎么能表示为图片呢?应该用file上传。

    除了引用的字体文件其他我好像也没改

    2020-06-23 13:45:45
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
PHP安全开发:从白帽角度做安全 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载
复杂PHP系统性能瓶颈排查及优化 立即下载