Yates WANG 2015-08-06 07:24 采纳率: 0%
浏览 2127

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);
?>

再次感谢!

  • 写回答

2条回答 默认 最新

  • threenewbee 2015-08-06 07:48
    关注
     <input type="text" name="text" id="text"/>
    

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

    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line